I want to pass variable n
from startpage
to page1
. Then put the variable into a label widget called label_country
. How can I do this within tkinter
? I tried calling the variable by the class and I also used the n.get()
method.
import tkinter as tk
from tkinter import ttk
class tkinterApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self, height=1000, width=1000, bg="gray")
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, Page1):
frame = F(container, self)
self.frames[F] = frame
frame.place(relx=0, rely=0, relwidth=1, relheight=1)
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent, bg="gray")
style = ttk.Style()
style.configure('W.TButton', foreground='black', background='white'
)
button = ttk.Button(self, text="slect a country ", style='W.TButton',
command=lambda: [ controller.show_frame(Page1)])
button.place(relx=0.66, rely=0.05, relwidth=0.2, relheight=0.07)
ttk.Label(self, text="country slect:").place(relx=0.14, rely=0.05, relwidth=0.5, relheight=0.07)
n = tk.StringVar()
country_choice = ttk.Combobox(self, width=27, textvariable=n)
country_choice["values"] = ([x for x in df["Country"].unique()])
country_choice.place(relx=0.14, rely=0.05, relwidth=0.5, relheight=0.07)
country_choice.current()
text_box = tk.Text(self, height=28, width=30, bg="white")
text_box.insert(tk.INSERT, "INFORMATIONT ABOUT THE PROGRAM")
text_box.config(state="disabled")
text_box.place(relx=0.14, rely=0.15, )
class Page1(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent, bg="gray")
label_country = tk.Label(self, text= StartPage.n, bg = "white")
label_country.place(relx=0.795, rely=0.13, relwidth=0.0755, relheight=0.03)
app = tkinterApp()
app.mainloop()