Tkinter is the standard Python interface to the Tk GUI (Graphical User Interface) toolkit.
It is included with Python and is cross-platform (works on Windows, macOS, and Linux).
Tkinter is easy to use and simple
Tkinter supports a wide range of widgets for building interactive interfaces.
Tkinter Setup:
import tkinter as tk
root = tk.Tk()
root.mainloop()
text_widget = tk.Text(root, height=10, width=30)
text_widget.pack()
from tkinter import PhotoImage
image = PhotoImage(file='image.png')
label = tk.Label(root, image=image)
label.pack()
def on_click():
print("Button clicked!")
button = tk.Button(root, text="Click Me", command=on_click)
button.pack()
entry = tk.Entry(root)
entry.pack()
label = tk.Label(root, text="Hello, Tkinter!")
label.pack()
listbox = tk.Listbox(root)
listbox.pack()
listbox.insert(tk.END, "Item 1")
listbox.insert(tk.END, "Item 2")
menu = tk.Menu(root)
root.config(menu=menu)
file_menu = tk.Menu(menu)
menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Exit", command=root.quit)
var = tk.StringVar()
radio_button1 = tk.Radiobutton(root, text="Option 1", variable=var,
value="1")
radio_button2 = tk.Radiobutton(root, text="Option 2", variable=var,
value="2")
radio_button1.pack()
radio_button2.pack()
var1 = tk.IntVar()
check_button = tk.Checkbutton(root, text="Option 1", variable=var1)
check_button.pack()
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
message_box = tk.Message(root, text="This is a text message box")
message_box.pack()
frame = tk.Frame(root)
frame.pack()
button1 = tk.Button(frame, text="Button 1")
button2 = tk.Button(frame, text="Button 2")
button1.pack(side=tk.LEFT)
button2.pack(side=tk.LEFT)
label = tk.Label(root, text="Pack Example")
label.pack()
label = tk.Label(root, text="Grid Example")
label.grid(row=0, column=0)
label = tk.Label(root, text="Place Example")
label.place(x=100, y=100)
def update_label():
label.config(text=entry.get())
label = tk.Label(root, text="Hello!")
label.pack()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="Update", command=update_label)
button.pack()
Made By SOU Student for SOU Students