Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Am just trying to return a value from a class method ?

Status
Not open for further replies.

richardiontton

Technical User
Feb 21, 2005
2
0
0
GB
Am just trying to return a value from a class method in the MyDialog class? Nothing seems to work?

All I wish to do is return a value from one class method to another using a dialog! surely I am missing something easy here.

# File example2.py

from Tkinter import *
import tkSimpleDialog

class 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)

def apply(self):
first = int(self.e1.get())
second = int(self.e2.get())
self.result= first, second
return self.result

class App:

def __init__(self,master):

frame = Frame(master)
frame.pack()

self.quit_but = Button(frame, text="Quit", fg="red", command=frame.quit)
self.quit_but.pack(side=LEFT)

self.dialog_but = Button(frame, text="Dialog", command= self.run_dialog)
self.dialog_but.pack(side=LEFT)

self.text = Text(master, width=30)
self.text.pack(side=LEFT)

def run_dialog(self):
d = MyDialog(root)
self.text.insert(END, d.apply())


root = Tk()
app=App(root)
root.mainloop()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top