Create Applications and/or Dialogs
By selecting "Main Window" or "Dialog" from the Main Form,
tk_happy will create python source code for either a main-window type application
or simply a dialog that will be called from an application.
Each project is given a name and tk_happy will save results files with the
project name as a file prefix. A project named "myApp", for example, will
save tk_happy information to "myApp.def". If the project is a "Main Window", the
python source code will be saved to "myApp.py". If "Dialog" is selected, the
python source code will be saved to "myApp_Dialog.py".
An example of source code created for a "Main Window" is shown on this sites
web page "Python Source".
The following is the bottom of a python source file for a dialog.
If the dialog file is run stand-alone, then a test application is run that calls the dialog.
Notice that the test function prints the results of the dialog with the line "print dialog.result"
class _Testdialog:
def __init__(self, master):
frame = Frame(master, width=300, height=300)
frame.pack()
self.master = master
self.x, self.y, self.w, self.h = -1,-1,-1,-1
self.Button_1 = Button(text="Test Dialog", relief="raised", width="15")
self.Button_1.place(x=84, y=36)
self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click)
def Button_1_Click(self, event):
dialog = _Entry(self.master, "Test Dialog")
print '===============Result from Dialog===================='
print dialog.result
print '====================================================='
def main():
root = Tk()
app = _Testdialog(root)
root.mainloop()
if __name__ == '__main__':
main()
The "validate" function returns the result of the dialog.
The default for tk_happy is to return a dictionary from the dialog, however, the user
can change the return value to anything they want.
def validate(self):
self.result = {}
self.result["info"] = self.Entry_1_StringVar.get()
return 1
tk_happy will create dialogs as well as applications.
Colorized listings thanks to ASPN Recipe at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442482 by Peter Krantz
|