嗨,任何人都可以帮助我吗?我是编程新手,我正在尝试使用 tkinter 做一个小项目。基本上我的问题是我怎样才能做到这一点,所以当我从组合框中选择一个选项时,也会选择 ttk 笔记本上的选项卡,反之亦然...提前致谢
import tkinter as tk
from tkinter import ttk
class Main(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
container = ttk.Frame(self)
container.grid()
frame = Frame(container, self)
frame.grid(column=0, row=0)
notebook = Notebook(container, self)
notebook.grid(column=1, row=0)
class Frame(ttk.Frame):
def __init__(self, parent, controller, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
combobox = ttk.Combobox(self)
combobox["values"] = ["a", "b", "c"]
combobox.grid()
class Notebook(ttk.Notebook):
def __init__(self, parent, controller, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
first = ttk.Frame(self)
second = ttk.Frame(self)
third = ttk.Frame(self)
self.add(first, text="a")
self.add(second, text="b")
self.add(third, text="c")
root = Main()
root.mainloop()