I want to navigate to the new screen after I click upon a button,this is working as a whole program, I mean if I write all the classes in a single file it works,but I want to organize the code with files so I created a new class and calling that class in the class of main file. But it outputs the blank screen. code of file Menu
from Page import MenuPage
class SampleApp(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.container = Frame(self)
self.container.pack()
self.frames = {}
for F in (StartPage, PageOne):
frame = F(self.container, self)
self.frames[F] = frame
frame.configure(width=2085, height=1080)
frame.config(bg='#020A2E')
frame.grid(row=0, column=0)
self.show_frame(StartPage)
def show_frame(self, controller):
frame = self.frames[controller]
frame.tkraise()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller=controller
canvas = Canvas(self,width=2085, height=1080, bg='#020A2E')
canvas.pack()
self.img = Image.open("images/b100.png")
self.my_img = ImageTk.PhotoImage(self.img)
canvas.create_image(200, 310, image=self.my_img, tags='close_tag')
self.imgg = Image.open("images/c100.png")
self.myimg = ImageTk.PhotoImage(self.imgg)
canvas.create_image(470, 310, image=self.myimg)
self.oimage = Image.open("images/o100.png")
self.omg = ImageTk.PhotoImage(self.oimage)
canvas.create_image(820, 310, image=self.omg)
self.timg = Image.open("images/t100.png")
self.tmg = ImageTk.PhotoImage(self.timg)
canvas.create_image(1150, 310, image=self.tmg)
canvas.create_text(665, 540, text="connect to headset", anchor=S, font='Arial 8 ', fill='white')
self.url = "wss://localhost:6868"
self.user = {
"license": "e2c901aa-0032-483e-976b-8d90957099ad",
"client_id": "uNU5UMKd9eFLYp8JtHr6ZXXaLHg1p6rf1BReVn4N",
"client_secret": "9wcDtQn2Wubjg7zzlO2tnkx8Hzk1GkLpqZsqgOiuaWsaI0VRkxcxeQ9ZOPrHrNvJ1tlgOAV1XEZ6ooxJ06sRwobXDApRsol08w9YsJWU0fVAieWYp6kHexOlM9OWqXWk",
"debit": 100
# "number_row_data" : 10
}
connect = Button(self,width=15, height=1, bd=0, bg='#2C3547', text="CONNECT", relief=RAISED,
font='Arial 10 bold ', fg='white', command=self.connection).place(x=600, y=500)
self.next = Image.open("images/next.png")
self.img_nxt = ImageTk.PhotoImage(self.next)
Button(self,width=35, height=30, bg='#020A2E', image=self.img_nxt, bd=0, command=lambda: controller.show_frame(PageOne)).place(x=1320, y=10)
def connection(self):
c = Cortex(self.url, self.user)
headset_id = c.query_headset()
c.connect_headset()
c.request_access()
messagebox.showinfo("BCOT", "headset connected")
auth = c.authorize()
c.create_session(auth, headset_id)
class PageOne(Frame):
def __init__(self,parent,controller):
Frame.__init__(self,parent)
self.controller=controller
m = MenuPage(parent,controller)
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
from the class PageOne I want to call another class which is present in different file called 'Page.py'-it has all the widgets and the items.so now I want to display all the code of Page.py in the PageOne class here is my Page.py file:
class MenuPage(Frame):
def __init__(self, parent, controller, **kw):
Frame.__init__(self,parent)
self.image1 = PhotoImage(file=r'images/iot.png')
self.image2 = PhotoImage(file=r'images/facialExp.png')
self.image3 = PhotoImage(file=r'images/cursor.png')
self.image4 = PhotoImage(file=r'images/mindR.png')
self.imgg = PhotoImage(file=r'images/arrow.png')
self.controller = controller
self.canvas = Canvas(self,width=2085, height=1080, bg='#020A2E')
self.canvas.pack()
label = Label(self,text="FEATURES", bg='#020A2E', fg='white', font='Arial 50 bold').place(x=80, y=20)
from Menu import StartPage
arrow = Button(self,width=40, height=30, bg='#020A2E', image=self.imgg, bd=0,
command=lambda:controller.show_frame(StartPage)).place(x=10, y=10)
button1 =Button(self,width=200, height=215, bg="#3A3535", bd=0, image=self.image1).place(x=380, y=150)
self.canvas.create_rectangle(75, 150, 380, 365, fill='#615A5A')
self.canvas.create_text(220, 160, text="TURN ON THE LIGHTS", anchor=N, font='Arial 14 bold', fill='white')
# label1= Label(root,text="TURN ON THE LIGHTS",fg='yellow',font='Arial 10 bold').place(x=100,y=160)
# label11 = Label(root,text="just move your head towards left and blink\nyour eye twice to open this feature or tap\nthe icon if you are using the cursor",fg='yellow',font='Arial 10 bold').place(x=90,y=200)
# canvas.create_rectangle(50,130,610,390,fill='#FFFFFF',stipple="gray12") #hover on tile1
button2 = Button(self,width=200, height=215, bg="#3A3535", bd=0, image=self.image2).place(x=1100, y=150)
self.canvas.create_rectangle(795, 150, 1101, 368, fill='#615A5A')
#label2 = tk.Label(text="TURN ON THE LIGHTS", fg='yellow', bg='#615A5A', font='Arial 10 bold').place(x=900,y=160)
# canvas.create_rectangle(770, 130,1325,390, fill='#FFFFFF')
button3 = Button(self,width=200, height=215, bg="#3A3535", bd=0, image=self.image3).place(x=380, y=450)
self.canvas.create_rectangle(75, 450, 380, 667, fill='#615A5A')
# canvas.create_rectangle(50,430,607,690,fill='#FFFFFF')
button4 = Button(self,width=200, height=215, bg="#3A3535", bd=0, image=self.image4).place(x=1100, y=450)
self.canvas.create_rectangle(795, 450, 1100, 669, fill='#615A5A')
# canvas.create_rectangle(770,430,1325,688,fill='#FFFFFF')
self.img = Image.open("images/sky.png")
self.my_img = ImageTk.PhotoImage(self.img)
self.my_rectangle = self.canvas.create_image(330, 255, image=self.my_img, tags='close_tag')
# my_rectangle=canvas.create_rectangle(50,130,610,390,fill="#FFFFFF", stipple="gray12")
parent.master.bind("<Left>", self.left)
parent.master.bind("<Right>", self.right)
parent.master.bind("<Up>", self.up)
parent.master.bind("<Down>", self.down)
def left(self, event):
x = -720
y = 0
# xx=event.xx
# yy=event.yy
pos = self.canvas.coords('close_tag')
if pos == [1050.0, 255.0] or pos == [1050.0, 555.0]:
print('left', pos)
self.canvas.move(self.my_rectangle, x, y)
def right(self, event):
x = 720
y = 0
pos = self.canvas.coords('close_tag')
if pos == [330.0, 255.0] or pos == [330.0, 555.0]:
print('right', pos)
self.canvas.move(self.my_rectangle, x, y)
def up(self, event):
x = 0
y = -300
pos = self.canvas.coords('close_tag')
if pos == [330.0, 555.0] or pos == [1050.0, 555.0]:
print('up', pos)
self.canvas.move(self.my_rectangle, x, y)
def down(self, event):
x = 0
y = 300
pos = self.canvas.coords('close_tag')
if pos == [330.0, 255.0] or pos == [1050.0, 255.0]:
print('down', pos)
self.canvas.move(self.my_rectangle, x, y)
I tried but i think the there is a conflict in the init function of PageOne and Page.py file's class so I am getting blank screen. I need your help guys