A brief description of how to use Tkinter for GUI programming.
fromTkinterImport*ImportTkinter.messagebox as MessageBox" "in the GUI, each button, Label, input box, and so on, is a widget. Frame is a widget that can accommodate other widgets, and all widgets are grouped together as a tree. The pack () method adds the widget to the parent container and implements the layout. Pack () is the simplest layout, and grid () allows for more complex layouts. In the Createwidgets () method, we create a label, two button, and a text box. When quit is clicked, triggering self.quit () causes the program to exit when Hello is clicked, triggering Self.hello (), displaying the message interface" "classApplication (Frame):def __init__(self,master=None): Frame.__init__(Self,master) Self.pack () self.createwidgets ()defcreatewidgets (self): Self.nameinput=Entry (self) self.nameInput.pack () Self.hellolabel=label (self,text='Hello World') Self.helloLabel.pack () Self.hellobutton=button (self,text='Hello', command=Self.hello) self.helloButton.pack () Self.quitbutton=button (self,text='Quit', command=self.quit) self.quitButton.pack ()defHello (self): name=self.nameinput.get ()or ' World'Messagebox.showinfo ('Message','Hello%s'%name)if __name__=='__main__': App=application ()" "Set Window caption" "App.master.title='liuruiqing' " "Main program Loop" "App.mainloop ()
Python graphical interface