import tkinter as tk root = tk.Tk() # creates a new window root.mainloop() # runs the main event loop
import tkinter as tk root = tk.Tk() label = tk.Label(root, text="Hello, World!") label.pack() root.mainloop()
import tkinter as tk def button_clicked(): print("Button clicked") root = tk.Tk() button = tk.Button(root, text="Click me!", command=button_clicked) button.pack() root.mainloop()This example adds a Button widget to the window using the Button() method and defines a function to be called when the button is clicked. Package library: tkinter