TK Inter
First window
from Import *
Tk (). Mainloop ()
The current thread calls Mainloop () and changes into the event loop, and the code behind is blocked.
If you want to create multiple windows
from Import *fromimport * for in range (5): Thread (Target= Tk (). Mainloop). Start ()print 2333sys.stdout.flush ()#2333
Create button
The Relxx property represents the relative value of the size of the main window 0~1
from Import *top=Tk () b=button (top,text='click') b.place ( Relx=0, rely=0.5, relwidth=1, relheight=0.1) Top.mainloop ()
Event handling
fromTkinterImport*Top=Tk () b=button (top,text='Click') B.place (Relx=0, rely=0.5, Relwidth=1, relheight=0.1)deffoo (event): Btn=Event.widget btn['text']='clicked!'B.bind ('<Button>', foo) Top.mainloop ()
You can also directly bind the callback method when you create the button (top, Command=foo) event callback when there is no event object, cannot operate the trigger button, is not recommended to use.
Tkinter of Python GUI development