Tkinter library in Python jhoj;i;iok.pptx

rundalomary12 6 views 17 slides Mar 04, 2025
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

tkinter


Slide Content

Tkinter library in Python

Spinbox checkbutton listbox Menu bar combobox Tkinter

Tkinter Spinbox checkbutton listbox Menu bar combobox

# Create a x menu # Add menu items to the x menu add_separator () Menu bar Create a menu bar

# Create a x menu # Add menu items to the x menu add_separator () Menu bar Create a menu bar

Menu bar menu_bar = Menu(parent) parent.config (menu= menu_bar ) Create a menu bar # Create a x menu # Add menu items to the x menu add_separator ()

Menu bar file_menu = Menu( menu_bar , tearoff =0) menu_bar.add_cascade (label=" File",menu = file_menu ) Create a menu bar # Create a x menu # Add menu items to the x menu add_separator ()

Menu bar file_menu.add_command (label="New") file_menu.add_command (label="Open") file_menu.add_command (label="Exit", command= parent.quit ) Create a menu bar # Create a x menu # Add menu items to the x menu add_separator ()

Menu bar file_menu.add_separator () Create a menu bar # Create a x menu # Add menu items to the x menu add_separator ()

# Create a x menu # Add menu items to the x menu add_separator () listbox # Create a Listbox to display contacts

Functions # Create "Add" and "Delete" buttons # Create an Entry widget to input new contacts listbox # Create a Listbox to display contacts contacts_listbox = tk.Listbox (root, selectmode = tk.SINGLE ) #Other possible values for selectmode include tk.BROWSE , tk.MULTIPLE , and tk.EXTENDED . contacts_listbox.pack ( padx =10, pady =10, fill= tk.BOTH , expand=True)

Functions # Create "Add" and "Delete" buttons # Create an Entry widget to input new contacts listbox # Create a Listbox to display contacts name_entry = tk.Entry (root) name_entry.pack ( pady =5)

Functions # Create "Add" and "Delete" buttons # Create an Entry widget to input new contacts listbox # Create a Listbox to display contacts add_button = tk.Button (root, text="Add", command= add_contact ) add_button.pack (side= tk.LEFT , padx =5) delete_button = tk.Button (root, text="Delete", command= delete_contact ) delete_button.pack (side= tk.LEFT , padx =5)

Functions # Create "Add" and "Delete" buttons # Create an Entry widget to input new contacts listbox # Create a Listbox to display contacts # Function to add a new contact to the Listbox def add_contact (): name = name_entry.get () if name: contacts_listbox.insert ( tk.END , name) name_entry.delete (0, tk.END ) # Function to delete the selected contact from the Listbox def delete_contact (): selected_index = contacts_listbox.curselection () if selected_index : contacts_listbox.delete ( selected_index )

# Create a x menu # Add menu items to the x menu add_separator () combobox Create a Combobox my_str_var = tk.StringVar () my_combobox = ttk.Combobox ( root, textvariable = my_str_var , values=["PHP", "Java", "Python"]) my_combobox.pack ()

# Create a x menu # Add menu items to the x menu add_separator () checkbutton checkbutton my_boolean_var = tk.BooleanVar () my_checkbutton = ttk.Checkbutton (text=["Check when the option True","1","2"], variable= my_boolean_var ) my_checkbutton.pack ()

# Create a x menu # Add menu items to the x menu add_separator () Spinbox Spinbox text_var = tk.DoubleVar () spin_box = tk.Spinbox ( root, from_=0.6, to=50.0, increment=.01, textvariable = text_var ) spin_box.pack ()
Tags