Python's built-in GUI library is tkinter. One of the easiest ways to create a user interface in tkinter is by using pre-built templates.
Here's an example of how to use a template in tkinter:
main.py712 chars26 lines
In this example, we create a new class Application
that is a subclass of Frame
. In __init__()
method of the class, we initialize the Frame
by calling the parent constructor with super().__init__(master)
. We also set self.master
to master
and then create the widgets using the create_widgets()
method.
Inside the create_widgets()
method, we create a ttk.Label()
widget with text "Hello, world!" and ttk.Button()
widget with text "Template Button". We also set command=self.template_function
to the button, which will call the template_function()
method when the button is clicked.
Finally, we create an instance of the Tk()
class and the Application
class, set the master
to root
, and start the main event loop with app.mainloop()
.
gistlibby LogSnag