w3resource

Python tkinter widgets Exercise: Add a button in your application using tkinter module

Python tkinter widgets: Exercise-1 with Solution

Write a Python GUI program to add a button in your application using tkinter module.

Sample Solution:

Python Code:

import tkinter as tk 
parent = tk.Tk() 
parent.title('Title - button') 
my_button = tk.Button(parent, text='Quit', height=1, width=35, command=parent.destroy) 
my_button.pack() 
parent.mainloop()

Sample Output:

Flowchart: Add a button in your application using tkinter module

Flowchart:

Flowchart: Add a button in your application using tkinter module

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Python tkinter widgets Exercise Home
Next: Write a Python GUI program to add a canvas in your application using tkinter module.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Getting rid of unwanted characters:

You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.

str="+++Welcome python+++"
str.strip()

print(str)

Output:

+++Welcome python+++