w3resource

Python tkinter Basic Exercise: Create a window and Set its title and add a label to the window

Python tkinter Basic: Exercise-2 with Solution

Write a Python GUI program to import Tkinter package and create a window. Set its title and add a label to the window.

Sample Solution:

Python Code:

import tkinter as tk
parent = tk.Tk()
parent.title("-Welcome to Python tkinter Basic exercises-")
my_label = tk.Label(parent, text="Label widget")
my_label.grid(column=0, row=0)
parent.mainloop()

Sample Output:

Tkinter: Import Tkinter package and create a window. Set its title and add a label to the window

Python Code Editor:

Previous: Write a Python GUI program to import Tkinter package and create a window and set its title.
Next: Write a Python GUI program to create a label and change the label font style (font name, bold, size) using tkinter module.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python-exercises/tkinter/python-tkinter-basic-exercise-2.php