Gui Flashcards
What does GUI stand for?
Graphical user interface
What Python module can be used to create a gui?
The Tkinter GUI module tool kit
Import everything from tkinter:
From tkinter import *
(The asteroid means everything)
Windows
Serves as a container to hold widgets
Widgets
GUI elements: buttons, text boxes, labels , images
Create a window called window with Tk
this instantiates an instance of a window
Window = Tk()
Display a window
places window on computer screen, listens for events
Window = Tk()
Window.mainloop()
Set a windows geometry(size) to 500x500
Window.tk()
Window.geometry(“500x500”)
Window.mainloop()
Change window title
Window.tk()
Window.geometry(“500x500”)
Window.title(“title”)
Window.mainloop()
Change icon for gui
Icon = PhotoImage(file=‘icon.png’)
Window.iconphoto(true,icon)
Configure your windows background to black
Window.config(background=“black”
Add a label to your window
Window =Tk()
Window.mainloop()
Label =label(window,text=‘HELLO’
Label.pack()#adds to window
Or
Label.place(x=0,y=0)
the first argument taken in by our label function is the name of our window variable (in this case it’s called window)
Change font of label
Label = label(window,text=“cum”,font=(‘fontype’, size,bold))
What other kwargs can be used in a label?
The relief eg. Relief= RAISED
fg=“colour”
bg=“colour”
Padx
Pady
Image=photo
Compound=“bottom”