This commit is contained in:
louiscklaw
2025-01-31 19:38:17 +08:00
parent b7e6ca17ef
commit 5ea2c37f8d
124 changed files with 3736 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
options = ['Option 1', 'Option 2', 'Option 3']
variable = tk.StringVar(value=options[0])
def on_option_changed(*args):
print('helloworld')
# This function will be called whenever the selected option changes
# We will use it to update the option list based on the selected option
# Get the selected option
selected_option = variable.get()
# Update the option list based on the selected option
if selected_option == 'Option 1':
new_options = ['Option 1', 'Option 2', 'Option 3']
elif selected_option == 'Option 2':
new_options = ['Option 4', 'Option 5', 'Option 6']
else:
new_options = ['Option 7', 'Option 8', 'Option 9']
# Update the option list in the widget
combobox.configure(values=new_options)
# Create the widget
combobox = ttk.Combobox(root, textvariable=variable, values=options)
combobox.pack()
# Bind the on_option_changed function to the variable
variable.trace('w', on_option_changed)
root.mainloop()