Posts

Showing posts from December, 2024

Python tkinter trick

This trick allows you to link a label's text directly to a variable, so the label updates automatically whenever the variable changes. Example: Dynamic Label with StringVar import tkinter as tk # Create the main window root = tk.Tk() root.title("Dynamic Label with StringVar") # Create a StringVar to hold the label's text dynamic_text = tk.StringVar() dynamic_text.set("Hello, Tkinter!") # Create a label that uses StringVar label = tk.Label(root, textvariable=dynamic_text, font=("Arial", 16)) label.pack(pady=20) # Function to update the label's text def update_text(): current_text = dynamic_text.get() dynamic_text.set(f"{current_text} 🎉") # Create a button to trigger the text update button = tk.Button(root, text="Update Text", command=update_text) button.pack(pady=10) # Run the application root.mainloop()

Daily quiz#1

Loading…

Python tabs using tkinter

Python TTK Tabs Tutorial In this tutorial, we’ll learn how to create tabs in Python using the ttk.Notebook widget from the tkinter library. Tabs are a great way to organize content in your GUI applications. Code Example # Import tkinter and ttk import tkinter as tk from tkinter import ttk # Create the main window root = tk.Tk() root.title("Bonedev Python TTK Tabs Example") # Create a Notebook widget (Tab container) notebook = ttk.Notebook(root) # Create two frames that will hold content for each tab frame1 = ttk.Frame(notebook) frame2 = ttk.Frame(notebook) # Add frames as tabs to the notebook notebook.add(frame1, text="Tab 1") notebook.add(frame2, text="Tab 2") # Add content to Tab 1 label1 = ttk.Label(frame1, text="This is the content of Tab 1.") label1.pack(padx=20, pady=20) # Add content to Tab 2 label2 = ttk.Label(frame2, text="This is the content of Tab 2.") label2.pack(padx=20, pady=20) # Pack the...