Posts

Python try Statments

How to Use try , except , and finally in Python (With a Little Humor) So, you’ve written some Python code and suddenly... BAM! An error crashes your program. Don’t panic! This is where try , except , and finally come in to save the day. 1. The try Block – "I’ll Try, but I Can’t Promise Anything!" The try block is where you place the code that might break (but you hope it doesn’t). You’re saying, “Hey Python, I’ll give this a try, but I’m not sure it’ll work!” try: # I'm trying to divide by zero. What could go wrong? 😅 result = 10 / 0 print(result) 2. The except Block – "Okay, That Didn’t Work, But Let’s Handle It!" When things go wrong in the try block, Python will raise an error. This is where the except block steps in like a superhero. except ZeroDivisionError: print("Oops! You can't divide by zero, silly!") 3. The finally Block – "No Matter What, I’ll Be There!" Now, even if something breaks, the...

MenuBars in py

 MenuBars In Python Example: 

Tkcode Magic

TKCODE Tutorial Type in your terminal: Example:

New Year Quiz- 2025

Loading…

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...