Python tkinter widgets Exercise: Create a Listbox bar widgets using tkinter module
Python tkinter widgets: Exercise-12 with Solution
Write a Python GUI program to create a Listbox bar widgets using tkinter module.
Sample Solution:
Python Code:
import tkinter as tk
parent = tk.Tk()
parent.geometry("250x200")
label1 = tk.Label(parent,text = "A list of favourite languages...")
listbox = tk.Listbox(parent)
listbox.insert(1,"PHP")
listbox.insert(2, "Python")
listbox.insert(3, "Java")
listbox.insert(4, "C#")
label1.pack()
listbox.pack()
parent.mainloop()
Explanation:
In the exercise above -
- import tkinter as tk - Import the Tkinter library (tkinter).
- parent.geometry("250x200") - Create the main Tkinter window (parent) and set its initial size to 250x200 pixels.
- label1 = tk.Label(parent,text = "A list of favourite languages...") - Create a Label widget (label1) with the text "A list of favorite languages...".
- listbox = tk.Listbox(parent) - Create a Listbox widget (listbox) to display a list of items.
- Insert four items ("PHP," "Python," "Java," "C#") into the Listbox.
- Use the pack() method to display the Label and Listbox widgets within the window.
- Start the Tkinter main loop to run the GUI application, displaying the labeled list of favorite languages.
Sample Output:
Flowchart:
Python Code Editor:
Previous: Write a Python GUI program to create a Progress bar widgets using tkinter module.
Next: Python GUI Program: Creating a tabbed interface with Tkinter.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
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://w3resource.com/python-exercises/tkinter/python-tkinter-widgets-exercise-12.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics