I want to have a frame with a input box, when the submit button next to it is pressed it submits the input and calls the function Add_Label
from class ChangedPage
where the function is added under and then raises the next frame where I want the label to appear.
The problem is I want the function I call to add a widget to the second class not the class I am calling it from. I have made a new program to demonstrate this issue:
import tkinter as tk
class Creating_Stuff(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
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 (PageTwo, ChangedPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(PageTwo)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
global bob
self.tk_setPalette(background='#bbfff0', foreground='black',
activeBackground='#d9d9d9', activeForeground='#ff9933')
self.controller = controller
title_2 = tk.Label(self, text= "Input Page #frame1", font = "Times 17 underline bold").place(relx = 0.5, rely = 0.1, relwidth = 0.4, anchor="center")
self.ENTRY = tk.Entry(self,width = 10, bg='white', fg='Black')
self.ENTRY.place(relx=0.5,rely=0.5,relwidth=0.3,anchor="center")
self.submit_button_2 = tk.Button(self, text="Submit Request", bg='#f2f2f2', command= self.raising)
self.submit_button_2.place(relx=0.4,rely=0.6,relwidth=0.2,anchor="center")
####Generic Stuff
Exit = tk.Button(self, text ="Exit",command=lambda:destroy(),bg='#f2f2f2')
Exit.place(relx=0.5,rely=(9/10), relwidth = 0.4, anchor="center")
def raising(self):
#Memes and stuff goes here
global bob
bob = self.ENTRY.get()
ChangedPage.Add_Label(self)
self.controller.show_frame(ChangedPage)
class ChangedPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
###Main stuff for the frames
self.title_27 = tk.Label(self, text= "Example Changed Page? #frame2", font = "Times 16 italic underline"
).place(relx = 0.36, rely = 0.05, relwidth = 0.4, anchor=tk.CENTER)
####Generic Stuff
bk2_Menu2 = tk.Button(self, text="Back to start",
command=lambda: controller.show_frame(PageTwo),bg='#f2f2f2')
bk2_Menu2.place(relx=0.5,rely=(0.8), relwidth = 0.2, anchor="center")
Exit = tk.Button(self, text ="Exit",command=lambda:destroy(),bg='#f2f2f2')
Exit.place(relx=0.5,rely=(9/10), relwidth = 0.4, anchor="center")
def Add_Label(self):
self.label1 = tk.Label(self, text= bob, font="Times 20")
self.label1.place(anchor = tk.CENTER, relx = 0.5, rely = 0.5, relwidth = 0.2, relheight = 0.1)
app = Creating_Stuff()
def destroy():
app.destroy()
app.tk_setPalette(background='#bbfff0', foreground='black',
activeBackground='#d9d9d9', activeForeground='#ff9933')
app.title("Example Label Adding Program")
app.geometry("800x450")
app.mainloop()
The code I have shown is a program with the first page with input boxes when you submit it will take you to the next frame and run the function from class ChangedPage
which is meant to make the label on the page that is just raised. Can anyone see what is going wrong?
Start Page is here:
Where it is meant to go here: