[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> 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> <BR> My first program called "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. 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> File "a.py" line 12, in ?<BR> import b<BR> File "b.py" line 4<BR> from import a <BR> <BR>My program is given below.</DIV>
<DIV>##########################################<BR>############# a.py<BR>##########################################</DIV>
<DIV>from Tkinter import *<BR>import b</DIV>
<DIV>class App:<BR> def __init__(self,parent):<BR> self.myparent = parent<BR> Button(self.myparent,text="Click",width=10,<BR>height=10,command=self.showdlg).pack()<BR> self.name = "AAAAA"<BR> self.no = 100</DIV>
<DIV> def showdlg(self):<BR> b.MyDialog(self.myparent)</DIV>
<DIV>root = Tk()<BR>myapp = App(root)<BR>root.mainloop()</DIV>
<DIV>##########################################<BR>############# 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> def body(self, master):</DIV>
<DIV> Label(master, text="First:").grid(row=0)<BR> Label(master, text="Second:").grid(row=1)</DIV>
<DIV> self.e1 = Entry(master)<BR> self.e2 = Entry(master)</DIV>
<DIV> self.e1.grid(row=0, column=1)<BR> self.e2.grid(row=1, column=1)<BR> self.e1.insert(0,a.myapp.name)<BR> self.e2.insert(0,a.myapp.no)</DIV>
<DIV> def apply(self):</DIV>
<DIV> first = (self.e1.get()) #string.atoi<BR> second = string.atoi(self.e2.get())<BR> print first, second # or something</DIV>
<DIV> Let me know where i gone wrong and correct my<BR>mistake.</DIV>
<DIV>Thanx</DIV>
<DIV> </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--