By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,403 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,403 IT Pros & Developers. It's quick & easy.

2 GUI Windows in Tkinter

P: 6
I am trying to make a simple dialog box, but when I run this, I get one black window in front of the working application window that I want. How do I get rid of that window?

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. import tkSimpleDialog
  3. from traders import QueryTrader
  4.  
  5. class Inputs(tkSimpleDialog.Dialog):              
  6.  
  7.     def body(self, master):
  8.         Label(master, text="Enter Environment Name:").grid(row=0)
  9.         Label(master, text="ID #:").grid(row=1)
  10.         Label(master, text="Enter Start Date for Query:").grid(row=2)
  11.         Label(master, text="Enter End Date for Query:").grid(row=3)
  12.         Label(master, text="Output File Location:").grid(row=4)
  13.  
  14.         self.e1 = Entry(master)
  15.         self.e2 = Entry(master)
  16.         self.e3 = Entry(master)
  17.         self.e4 = Entry(master)
  18.         self.e5 = Entry(master)
  19.  
  20.         self.e1.grid(row=0, column=1)
  21.         self.e2.grid(row=1, column=1)
  22.         self.e3.grid(row=2, column=1)
  23.         self.e4.grid(row=3, column=1)
  24.         self.e5.grid(row=4, column=1)
  25.         return self.e1
  26.  
  27.     def apply(self):
  28.         MXSess = int(self.e1.get())
  29.         Id = int(self.e2.get())
  30.         startDate = int(self.e3.get())
  31.         endDate = int(self.e4.get())
  32.         output = int(self.e5.get())
  33.  
  34.         new = Query()
  35.         arr = new.loadFiles(MXSess, startDate, endDate, Id)
  36.         new.searchDocs(arr, output)
  37.  
  38. root = Tk()        
  39. root.title('Input Parameters')
  40. d = Inputs(root)
  41.  
Sep 1 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 622
First, you have to pass the Tk() instance to your class. Second, you are not using SimpleDialog so there is no reason to inherit it. Take another look at where you got the code and see what they did and did not do. Some modified code that you can start with follows. Tkinter tutorials/references:
http://infohost.nmt.edu/tcc/help/pub...ter/index.html
http://effbot.org/tkinterbook/
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. ##import tkSimpleDialog
  3. ##from traders import QueryTrader
  4.  
  5. class Inputs():              
  6. ##class Inputs(tkSimpleDialog.Dialog):              
  7.  
  8.     def __init__(self, master):
  9.         self.body(master)
  10.  
  11.     def body(self, master):
  12.         Label(master, text="Enter Environment Name:").grid(row=0)
  13.         Label(master, text="ID #:").grid(row=1)
  14.         Label(master, text="Enter Start Date for Query:").grid(row=2)
  15.         Label(master, text="Enter End Date for Query:").grid(row=3)
  16.         Label(master, text="Output File Location:").grid(row=4)
  17.  
  18.         self.e1 = Entry(master)
  19.         self.e2 = Entry(master)
  20.         self.e3 = Entry(master)
  21.         self.e4 = Entry(master)
  22.         self.e5 = Entry(master)
  23.  
  24.         self.e1.grid(row=0, column=1)
  25.         self.e2.grid(row=1, column=1)
  26.         self.e3.grid(row=2, column=1)
  27.         self.e4.grid(row=3, column=1)
  28.         self.e5.grid(row=4, column=1)
  29.  
  30.         ##----- you don't have to return as "self." variables
  31.         ##      are global within the class
  32.         ##return self.e1
  33.  
  34.     def apply(self):
  35.         MXSess = int(self.e1.get())
  36.         Id = int(self.e2.get())
  37.         startDate = int(self.e3.get())
  38.         endDate = int(self.e4.get())
  39.         output = int(self.e5.get())
  40.  
  41. ##        new = Query()
  42. ##        arr = new.loadFiles(MXSess, startDate, endDate, Id)
  43. ##        new.searchDocs(arr, output)
  44.  
  45. root = Tk()        
  46. root.title('Input Parameters')
  47. d = Inputs(root)
  48. root.mainloop() 
Sep 1 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.