Sguigee

A GUI library for Python


Tuomas Laakkonen, 2015

Available on Github

Based on TKInter

Split into two levels

We're doing the easy version

So why not just use TKInter?


Code first

ask questions later

A Simple 'Hello World' Example

import tkinter as tk

t = tk.Tk()
t.title('Hello World')
x = tk.Label(t, 
  text='Hello World')
x.pack(fill='x', expand=True, 
  side='left')
t.mainloop()
from sguigee import window, label

with window(title='Hello World'):
  label('Hello World')
  

So how do we use it?


  • Windows are the base unit


  • A Window divides into Rows


  • Rows Stack

An example


Example: Calculator


from gui import window, row, button, textbox
import operator as op

def make_button(text):
  @button(text)
  def _button():
    output.set(output.get() + text)
  return _button
  
def make_operator(t, op):
  @button(t, expand=False, use_monospace_font=True)
  def _button():
    stack.append(float(output.get()))
    output.set('')
    stack.append(op)
    
stack = []
with window(title="Calculator", set_minimum_size=True, can_resize=False):
  with row():
    output = textbox()
    
  with row():
    make_button('1')
    make_button('2')
    make_button('3')
    make_operator('+', op.add)
    
  with row():
    make_button('4')
    make_button('5')
    make_button('6')
    make_operator('-', op.sub)
    
  with row():
    make_button('7')
    make_button('8')
    make_button('9')
    make_operator('*', op.mul)
    
  with row():
    make_button('0')
    make_button('.')
    make_operator('/', op.truediv)
    
  with row():
    @button('Clear')
    def clear():
      output.set('')
      
    @button('Clear All')
    def clear_all():
      stack = []
      output.set('')
      
    @button('=')
    def compute():
      while len(stack) >= 2:
        op, lhs = stack.pop(), stack.pop()
        output.set(op(lhs, float(output.get())))
        

Lets Get Started!

The 'With' Statement


Windows


Rows


Let's combine the two!


with window(title="Title"):
  with row():
    pass
  with row():
    pass
    

But I have no actual content!

Labels


Lets put this all together!


Note: All elements Must be in a row!

Textboxes


Lets try this!

Because code can only execute when the user does something!

So... How do we do anything?


Buttons!


What's with the '@' thingy?


Now can we put it all together?


Did it work?


Another thing about text boxes


Canvas


Some more things: Message boxes


Dialog Boxes


Timers


How do we design a program that uses Sguigee?


Simple steps to follow:

Questions?

Now go code!

Challenge 1


Write a program to add two numbers.

The program should: