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()
-
-
5 15733 bvdet 2,851
Expert Mod 2GB master.withdraw() hides a top level window.
bvdet 2,851
Expert Mod 2GB
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()
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.
bvdet 2,851
Expert Mod 2GB
You're welcome. I learned a couple of things myself.
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()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Benson |
last post by:
Hi, I'm using Tkinter and would like to know how to replace the red "Tk"
logo in the left corner of the title bar of the root window with some other
icon.
Another question for curiosity's sake:...
|
by: george |
last post by:
Greetings to all experts.
I'm running Python 2.3/Pythonwin 1.63 on Windows 98. I would like to
create a window with Tkinter, that is always on top of the screen.
In Tkinter.py, Line 1375 f.,...
|
by: engsolnorm |
last post by:
I'm playing with a sudoku GUI...just to learn more about python.
I've made 81 'cells'...actually small canvases
Part of my scheme to write the cells (all 81 of them in the gui) to a file (using...
|
by: comp.lang.tcl |
last post by:
set php {<? print_r("Hello World"); ?>}
puts $php; # PRINTS OUT <? print_r("Hello World"); ?>
puts
When I try this within TCL I get the following error:
|
by: Joe Peterson |
last post by:
I've been doing a lot of searching on the topic of one of Python's more
disturbing issues (at least to me): the fact that if a __del__ finalizer
is defined and a cyclic (circular) reference is...
|
by: Adam |
last post by:
Hello,
I have a small app I am creating to crawl a directory and check that
if it is moved to another a location it's path will not break a
character limit. Usually the Windows path limit.
...
|
by: Miki |
last post by:
Hello,
Tk.lift doesn't seem to work on OSX (Python 2.5.1).
The below starts OK, but the window is the behind all other windows.
from Tkinter import *
root = Tk()
Button(root, text="OK",...
|
by: Pierre Dagenais |
last post by:
from Tkinter import *
win = Tk()
If I type those two lines at the command prompt (in WindowsXP) I get a
new window on my screen. Yet if I copy those lines in a file called
test.py and then...
|
by: merrygreat |
last post by:
#!/usr/bin/perl
use Tk;
my $window = MainWindow->new;
$window->title("Host Access Report");
($lab = $window->Label(-text => "Results go here"))->pack;
$window->Entry(-textvariable => \$nnn...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |