richardiontton
Technical User
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()
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()