[Tutor] Assigning values to dialog box entry widgets.....................

Python-lover hemanexp@yahoo.com
Tue May 6 14:15:25 2003


--0-1496109714-1052244811=:3037
Content-Type: text/plain; charset=us-ascii

Hi,
   Iam using python and tkinter. My program run number
of lines. To increase the maintainablity i divided my
program in to two modules (ie, 2 python programs) and
imported them at needed place.
   
   My first program called  "a.py" is the main program
in which i placed a button. When u click the button a
dialogbox which is defined in "b.py" will be poped up.
The dialog box contains two entry widgets.  Now the
problem is i want to set some default values for the
entry widgets when they displayed. I defined 2 
variables called "name" ,"eno" in "a.py" and want to
assign their values to corresponding entry widgets.
When i run the program i got the following error:    File "a.py" line 12, in ?
         import b
    File "b.py" line 4
 from import  a 
 
My program is given below.##########################################
#############  a.py
##########################################from Tkinter import *
import bclass App:
 def __init__(self,parent):
  self.myparent = parent
  Button(self.myparent,text="Click",width=10,
height=10,command=self.showdlg).pack()
  self.name = "AAAAA"
  self.no = 100 def showdlg(self):
  b.MyDialog(self.myparent)root = Tk()
myapp =  App(root)
root.mainloop()##########################################
#############  b.py
##########################################import tkMessageBox
import tkSimpleDialog
from Tkinter import *
import a
import stringclass MyDialog(tkSimpleDialog.Dialog):    def body(self, master):        Label(master, text="First:").grid(row=0)
        Label(master, text="Second:").grid(row=1)        self.e1 = Entry(master)
        self.e2 = Entry(master)        self.e1.grid(row=0, column=1)
        self.e2.grid(row=1, column=1)
 self.e1.insert(0,a.myapp.name)
 self.e2.insert(0,a.myapp.no)    def apply(self):        first = (self.e1.get()) #string.atoi
        second = string.atoi(self.e2.get())
        print first, second # or something Let me know where i gone wrong and correct my
mistake.Thanx 

---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
--0-1496109714-1052244811=:3037
Content-Type: text/html; charset=us-ascii

<DIV>Hi,<BR>&nbsp;&nbsp; Iam using python and tkinter. My program run number<BR>of lines. To increase the maintainablity i divided my<BR>program in to two modules (ie, 2 python programs) and<BR>imported them at needed place.<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; My first program called&nbsp; "a.py" is the main program<BR>in which i placed a button. When u click the button a<BR>dialogbox which is defined in "b.py" will be poped up.<BR>The dialog box contains two entry widgets.&nbsp; Now the<BR>problem is i want to set some default values for the<BR>entry widgets when they displayed. I defined 2 <BR>variables called "name" ,"eno" in "a.py" and want to<BR>assign their values to corresponding entry widgets.<BR>When i run the program i got the following error:</DIV>
<DIV>&nbsp;&nbsp;&nbsp; File "a.py" line 12, in ?<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; import b<BR>&nbsp;&nbsp;&nbsp; File "b.py" line 4<BR>&nbsp;from import&nbsp; a&nbsp;<BR>&nbsp;<BR>My program is given below.</DIV>
<DIV>##########################################<BR>#############&nbsp; a.py<BR>##########################################</DIV>
<DIV>from Tkinter import *<BR>import b</DIV>
<DIV>class App:<BR>&nbsp;def __init__(self,parent):<BR>&nbsp;&nbsp;self.myparent = parent<BR>&nbsp;&nbsp;Button(self.myparent,text="Click",width=10,<BR>height=10,command=self.showdlg).pack()<BR>&nbsp;&nbsp;self.name = "AAAAA"<BR>&nbsp;&nbsp;self.no = 100</DIV>
<DIV>&nbsp;def showdlg(self):<BR>&nbsp;&nbsp;b.MyDialog(self.myparent)</DIV>
<DIV>root = Tk()<BR>myapp =&nbsp; App(root)<BR>root.mainloop()</DIV>
<DIV>##########################################<BR>#############&nbsp; b.py<BR>##########################################</DIV>
<DIV>import tkMessageBox<BR>import tkSimpleDialog<BR>from Tkinter import *<BR>import a<BR>import string</DIV>
<DIV>class MyDialog(tkSimpleDialog.Dialog):</DIV>
<DIV>&nbsp;&nbsp;&nbsp; def body(self, master):</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Label(master, text="First:").grid(row=0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Label(master, text="Second:").grid(row=1)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.e1 = Entry(master)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.e2 = Entry(master)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.e1.grid(row=0, column=1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.e2.grid(row=1, column=1)<BR>&nbsp;self.e1.insert(0,a.myapp.name)<BR>&nbsp;self.e2.insert(0,a.myapp.no)</DIV>
<DIV>&nbsp;&nbsp;&nbsp; def apply(self):</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first = (self.e1.get()) #string.atoi<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; second = string.atoi(self.e2.get())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print first, second # or something</DIV>
<DIV>&nbsp;Let me know where i gone wrong and correct my<BR>mistake.</DIV>
<DIV>Thanx</DIV>
<DIV>&nbsp;</DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/search/mailsig/*http://search.yahoo.com">The New Yahoo! Search</a> - Faster. Easier. Bingo.
--0-1496109714-1052244811=:3037--