Se pravi imamo main window, na katerem je gumb , ki odpre novo okno in skrije main window. -> to deluje
Na novem oknu je tudi gumb, ki naj bi zapru to novo okno in nazaj prikazal glavno okno. -> to deluje na pol.
Glavno okno se prikaže, noče pa zapreti novega okna in javi spodnjo napako?
Vrstica, na katero se napaka nanaša je odebeljena.
def mfs(self):
root.deiconify()
newwin.withdraw()
Kaka ideja kako tole spravit v pravilno delovanje?
newwin.withdraw()
NameError: name 'newwin' is not defined
- Koda: Izberi vse
from tkinter import *
class Frames(object):
def newFrame(self):
newwin = Toplevel(root)
newwin.title('New Window')
newwin.geometry("200x100")
newwin.resizable(0, 0)
display = Label(newwin, text="Hello, " + self.query.get()) #getting parameter via query var
display.pack()
button2 =Button(newwin, text ="Open and Send New Window", command = self.mfs)
button2.place(x = 15, y = 25, width=170, height=25)
root.withdraw()
def mainFrame(self,root):
self.query = StringVar() #passing parameter via query var
root.title('Open Window!!!')
root.geometry("200x200")
root.resizable(0, 0)
button1 =Button(root, text ="Open and Send New Window", command =self.newFrame)
button1.place(x = 15, y = 25, width=170, height=25)
entry1 = Entry(root, textvariable=self.query)
entry1.place(x = 50, y = 75, width=100, height=25)
def mfs(self):
root.deiconify()
newwin.withdraw()
root = Tk()
app = Frames()
app.mainFrame(root)
root.mainloop()