menu_maker_Dialog.py


directory : D:\2018_py_proj\TkGridGUI\tkgridgui
Line Count : 137
Line Clip Size : No Clipping

tab_of_notebook_changed  Word MatchCase (0) 
1 #!/usr/bin/env python 2 # -*- coding: ascii -*- 3 from __future__ import print_function 4 from __future__ import unicode_literals 5 6 # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section top 7 8 from future import standard_library 9 standard_library.install_aliases() 10 from builtins import object 11 import sys 12 13 if sys.version_info < (3,): 14 from tkSimpleDialog import Dialog 15 else: 16 from tkinter.simpledialog import Dialog 17 18 from tkinter import * 19 20 class _Dialog(Dialog): 21 # use dialogOptions dictionary to set any values in the dialog 22 def __init__(self, parent, title = None, dialogOptions=None): 23 self.dialogOptions = dialogOptions 24 Dialog.__init__(self, parent, title) 25 26 class Menumaker(_Dialog): 27 28 def buttonbox(self): 29 pass 30 # this dummy routine overrides the standard "OK" and "Cancel" buttons 31 # REMEMBER!!! to call self.ok() and self.cancel() in User Code 32 33 def body(self, master): 34 dialogframe = Frame(master, width=300, height=500) 35 dialogframe.pack() 36 37 self.Button_1 = Button(dialogframe,text="Save Menu", relief="raised", width="15") 38 self.Button_1.place(x=24, y=12) 39 self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click) 40 41 self.Button_2 = Button(dialogframe,text="Exit Without Saving", relief="raised", width="15") 42 self.Button_2.place(x=173, y=12) 43 self.Button_2.bind("<ButtonRelease-1>", self.Button_2_Click) 44 45 self.Label_1 = Label(dialogframe,pady="1", text="Be Consistent with Indents", width="30") 46 self.Label_1.place(x=60, y=72) 47 48 self.ctrl_keyChkBox_StringVar = StringVar() 49 self.ctrl_keyChkBox = Checkbutton(dialogframe, text="Create ctrl-key shortcuts", width="30") 50 self.ctrl_keyChkBox.place(x=24 ,y=90 ) 51 self.ctrl_keyChkBox.configure( onvalue="yes", offvalue="no", variable=self.ctrl_keyChkBox_StringVar) 52 self.ctrl_keyChkBox_StringVar.set("yes") 53 54 self.Message_1 = Message(dialogframe,text="Indent Text To Show Menu Structure", aspect="1000", relief="flat") 55 self.Message_1.place(x=57, y=46) 56 57 self.Text_1 = Text(dialogframe,padx="1", width="35", height="30") 58 self.Text_1.place(x=12, y=120) 59 # >>>>>>insert any user code below this comment for section top 60 if self.dialogOptions: 61 self.Text_1.insert(END, self.dialogOptions ) 62 63 64 def Master_Configure(self, event): 65 if event.widget != self.master: 66 if self.w != -1: 67 return 68 x = self.master.winfo_x() 69 y = self.master.winfo_y() 70 w = self.master.winfo_width() 71 h = self.master.winfo_height() 72 if (self.x, self.y, self.w, self.h) == (-1,-1,-1,-1): 73 self.x, self.y, self.w, self.h = x,y,w,h 74 #if self.w!=w or self.h!=h: 75 # print( "Master reconfigured... make resize adjustments" ) 76 #print( "executed method Master_Configure" ) 77 78 def Button_1_Click(self, event): #click method for component ID=1 79 #print( "executed method Button_1_Click" ) 80 self.ok() 81 82 def Button_2_Click(self, event): #click method for component ID=2 83 #print( "executed method Button_2_Click" ) 84 self.cancel() 85 86 def validate(self): 87 self.result = {} # return a dictionary of results 88 # >>>>>>insert any user code below this comment for section dialog_validate 89 # set values in "self.result" dictionary for return 90 # for example... 91 # self.result["age"] = self.Entry_2_StringVar.get() 92 93 self.result["test"] = "test message" 94 #self.result["menu"] = ascii( self.Text_1.get(1.0, END) ) 95 self.result["menu"] = self.Text_1.get(1.0, END) 96 97 self.result["add_menu_ctrl_keys"] = self.ctrl_keyChkBox_StringVar.get() 98 99 if sys.version_info >= (3,): 100 #self.result["menu"] = self.result["menu"].encode( 'utf-8' ) 101 #self.result["menu"] = bytes(self.result["menu"], 'ascii') 102 pass 103 104 #print('menu = ', self.result["menu"] ) 105 #print('repr(menu) = ', repr(self.result["menu"])) 106 return 1 107 # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section end 108 109 110 def apply(self): 111 #print( 'apply called in menu_maker_Dialog' ) 112 pass 113 114 class _Testdialog(object): 115 def __init__(self, master): 116 frame = Frame(master, width=300, height=300) 117 frame.pack() 118 self.master = master 119 self.x, self.y, self.w, self.h = -1,-1,-1,-1 120 121 self.Button_1 = Button(text="Test Dialog", relief="raised", width="15") 122 self.Button_1.place(x=84, y=36) 123 self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click) 124 125 def Button_1_Click(self, event): #click method for component ID=1 126 dialog = Menumaker(self.master, "Test Dialog",'File\n New\n Save') 127 print( '===============Result from Dialog====================' ) 128 print( dialog.result ) 129 print( '=====================================================' ) 130 131 def main(): 132 root = Tk() 133 app = _Testdialog(root) 134 root.mainloop() 135 136 if __name__ == '__main__': 137 main() 138