hi guys anyone can help me? Im new to programming and Im trying to do a small project using tkinter.. basically my problem is how can I make it so when I choose an option from a combobox the tab on the ttk notebook will also be selected and vice versa... thanks in advance
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()
Try below full code,
Some modifications are made,
above code is used to take the selection events of notebook and combobox
Above two functions are made to handle both events
combobox values are put in a variable list "Options"