Python Tkinter GUI program: Adding labels and buttons
Python tkinter Basic: Exercise-6 with Solution
Write a Python GUI program that adds labels and buttons to the Tkinter window.
import tkinter as tk # Create the main window parent = tk.Tk() parent.title("Button Click Event Handling") # Create a label widget label = tk.Label(parent, text="Click the button and check the label text:") label.pack() # Function to handle button click event def on_button_click(): label.config(text="Button Clicked!") # Create a button widget button = tk.Button(parent, text="Click Me", command=on_button_click) button.pack() # Start the Tkinter event loop parent.mainloop()
In the exercise above the code creates a simple “Tkinter” window with a label that says " Tkinter basic exercises!" and a button that says " Click here!" When you click the button, the label text will change to "Button Clicked!".
Python Code Editor:Previous: Adding labels and buttons.
Next: Python Tkinter event handling: Button clicks.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Python: Tips of the Day
Summing a sequence of numbers (calculating the sum of zero to ten with skips):
>>> l = range(0,10,2) >>> sum(l) 20
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook