I trying to use class to create multiple tkinter notebook tabs. But i can only make one tab at once.
from tkinter import *
from tkinter import ttk
class Tabs:
current_tab = Frame(notebook)
current_entry = None
current_from = StringVar()
current_to = StringVar()
result = StringVar()
def __init__(self, name: str, units,calc_mode: str):
self.name = name
self.units = units
self.calc_mode = calc_mode
def create_frame(self):
notebook.add(self.current_tab, text=self.name)
Label(self.current_tab, text=self.name, font=("Arial", 30, "bold"), pady=20, padx=60).grid(row=0, column=1, columnspan=3)
Label(self.current_tab, text="From: ", font=("Arial", 18, "bold")).grid(row=1, column=0)
self.current_entry = Entry(self.current_tab, font="arial")
self.current_entry.grid(row=1, column=2)
self.current_from.set("Select")
OptionMenu(self.current_tab,self.current_from,*self.units.keys()).grid(row=1, column=3)
Label(self.current_tab, text="To: ", font=("Arial", 18, "bold")).grid(row=2, column=0)
self.current_to.set("Select")
OptionMenu(self.current_tab, self.current_to, *self.units.keys()).grid(row=2, column=2)
Label(self.current_tab, text="Result: ", font=("Arial", 18, "bold", "italic"), width=10).grid(row=4,column=0)
self.result.set("")
print_result = Label(self.current_tab, textvariable=self.result, font=("Arial", 28, "bold"))
print_result.grid(row=4, column=2)
Button(self.current_tab, text="Calculate", font=("Arial", 18, "italic"), pady=4, command=self.calculate).grid(row=3,column=2)
And it always shows the last one (for example the length tab here)
tempertaure_tab = Tabs("Temperature",temp_units,"temperature")
tempertaure_tab.create_frame()
length_tab = Tabs("Length",length_units,"normal")
length_tab.create_frame()
So that is my problem
New contributor
lorinctekker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.