|
P: 7
|
Hi, I am writing a program, in which everything interesting happens in a Toplevel window that I have made. However, whenever I run the program, I get both the standard Tk window and the Toplevel window that I made. How do I get rid of the first Tk window, without closing out of the program completely?
Thanks -
-
#Merthe's Ellipse Adjustment Program February 2012
-
-
import numpy
-
import scipy
-
-
from Tkinter import *
-
import tkFileDialog as tkf
-
-
filenames = {}
-
-
class App:
-
def __init__(self, master):
-
-
top = Toplevel()
-
top.title("Adjust Ellipse")
-
-
self.top = top
-
-
self.L0 = Label(top, text = "Initial Data:").grid(row=0,column=0, sticky=E)
-
self.L1 = Label(top, text = "After Change #1:").grid(row=1,column=0, sticky=E)
-
self.L2 = Label(top, text = "After Change #2:").grid(row=2,column=0, sticky=E)
-
self.L3 = Label(top, text = "Current State:").grid(row=3,column=0, sticky=E)
-
-
self.Name0 = Entry(top, state = "readonly", width=40).grid(row=0,column=1, sticky=W,columnspan=3)
-
self.Name1 = Entry(top, state = "readonly", width=40).grid(row=1,column=1, sticky=W,columnspan=3)
-
self.Name2 = Entry(top, state = "readonly", width=40).grid(row=2,column=1, sticky=W,columnspan=3)
-
self.Name3 = Entry(top, state = "readonly", width=40).grid(row=3,column=1, sticky=W,columnspan=3)
-
-
self.Butt0 = Button(top, text = "Select", command=self.openfile0).grid(row=0,column=4)
-
self.Butt1 = Button(top, text = "Select", command=self.openfile1).grid(row=1,column=4)
-
self.Butt2 = Button(top, text = "Select", command=self.openfile2).grid(row=2,column=4)
-
self.Butt3 = Button(top, text = "Select", command=self.openfile3).grid(row=3,column=4)
-
-
def openfile0(self):
-
tkf.askopenfile()
-
-
def openfile1(self):
-
tkf.askopenfile()
-
-
def openfile2(self):
-
tkf.askopenfile()
-
-
def openfile3(self):
-
tkf.askopenfile()
-
-
root = Tk()
-
-
app = App(root)
-
-
root.mainloop()
-
-
| |
Share this Question
| Expert Mod 2.5K+
P: 2,509
| master.withdraw() hides a top level window.
| | | Expert Mod 2.5K+
P: 2,509
|
This will hide the root window and return to it if the user chooses to close the TopLevel window: - class App:
-
def __init__(self, master=None):
-
self.master = master
-
master.state("withdraw")
-
top = Toplevel()
-
top.protocol("WM_DELETE_WINDOW", self.exit)
-
top.title("Adjust Ellipse")
-
self.top = top
Method exit: - def exit(self):
-
self.master.deiconify()
-
self.top.destroy()
| | |
P: 7
|
Big thanks bvdet. This is the part that I ended up using: -
top = Toplevel()
-
top.title("Adjust Ellipse")
-
top.protocol("WM_DELETE_WINDOW", self.exit)
-
-
self.master = master
-
master.withdraw()
-
Along with the method: -
def exit(self):
-
self.master.deiconify()
-
self.master.destroy() #Exit all when 'top' is closed
-
This does exactly what I wanted. Thanks again.
| | | Expert Mod 2.5K+
P: 2,509
|
You're welcome. I learned a couple of things myself.
| | | Expert 100+
P: 335
|
The simple solution is to use "master" instead of creating a new Toplevel. Then you don't have to go through the additional gyrations to close the master GUI. - from Tkinter import *
-
import tkFileDialog as tkf
-
-
filenames = {}
-
-
class App:
-
def __init__(self, top):
-
-
# top = Toplevel()
-
top.title("Adjust Ellipse")
-
-
self.top = top
-
-
self.L0 = Label(top, text = "Initial Data:").grid(row=0,column=0, sticky=E)
-
self.L1 = Label(top, text = "After Change #1:").grid(row=1,column=0, sticky=E)
-
self.L2 = Label(top, text = "After Change #2:").grid(row=2,column=0, sticky=E)
-
self.L3 = Label(top, text = "Current State:").grid(row=3,column=0, sticky=E)
-
-
self.Name0 = Entry(top, state = "readonly", width=40).grid(row=0,column=1, sticky=W,columnspan=3)
-
self.Name1 = Entry(top, state = "readonly", width=40).grid(row=1,column=1, sticky=W,columnspan=3)
-
self.Name2 = Entry(top, state = "readonly", width=40).grid(row=2,column=1, sticky=W,columnspan=3)
-
self.Name3 = Entry(top, state = "readonly", width=40).grid(row=3,column=1, sticky=W,columnspan=3)
-
-
self.Butt0 = Button(top, text = "Select", command=self.openfile0).grid(row=0,column=4)
-
self.Butt1 = Button(top, text = "Select", command=self.openfile1).grid(row=1,column=4)
-
self.Butt2 = Button(top, text = "Select", command=self.openfile2).grid(row=2,column=4)
-
self.Butt3 = Button(top, text = "Select", command=self.openfile3).grid(row=3,column=4)
-
-
def openfile0(self):
-
tkf.askopenfile()
-
-
def openfile1(self):
-
tkf.askopenfile()
-
-
def openfile2(self):
-
tkf.askopenfile()
-
-
def openfile3(self):
-
tkf.askopenfile()
-
-
root = Tk()
-
-
app = App(root)
-
-
root.mainloop()
| | Post your reply Help answer this question
Didn't find the answer to your Python question?
| | Question stats - viewed: 272
- replies: 5
- date asked: Feb 15 '12
|