def _interface_init(self): """ 界面初始化 :return: """ # ##################################################### # Create base frame that is an instance. self.window = tk.Tk() self.window.title("视频爬虫") # Add a title self.window.resizable(0, 0) # Disable resizing the GUI self.window.protocol('WM_DELETE_WINDOW', self._close_window) # ##################################################### # Tab Control self.tabControl = tk.ttk.Notebook(self.window) # Create Tab Control self.tab_yidian = tk.ttk.Frame(self.tabControl) # Create a tab self.tabControl.add(self.tab_yidian, text='一点视频') # Add the tab self.tab_watermelon = tk.ttk.Frame( self.tabControl) # create the tab for the watermelon self.tabControl.add(self.tab_watermelon, text="西瓜视频") # add into the tab. # self.tab_first = tk.ttk.Frame(self.tabControl) # Create a tab # self.tabControl.add(self.tab_first, text='第一个') # Add the tab # # self.tab_xigua = ttk.Frame(self.tabControl) # Add a second tab # self.tabControl.add(self.tab_xigua, text='西瓜视频') # Make second tab visible # # self.tab_unknown = ttk.Frame(self.tabControl) # Add a third tab # self.tabControl.add(self.tab_unknown, text='未知') # Make second tab visible self.tabControl.pack(expand=1, fill="both") # Pack to make visible # ##################################################### # tab_yidian self.frame_method = ttk.LabelFrame(self.tab_yidian, text='方法设置') self.frame_method.grid(column=0, row=0, padx=4, pady=4) # three methods values = ["按类别爬取", "按用户爬取", "按地址爬取"] # # create three Radiobuttons using one variable self.yidian_method = tk.IntVar() # Selecting a non-existing index value for radVar self.yidian_method.set(0) tk.Radiobutton(self.frame_method, text=values[0], variable=self.yidian_method, value=0).grid(column=0, row=1, sticky=tk.W) tk.Radiobutton(self.frame_method, text=values[1], variable=self.yidian_method, value=1).grid(column=0, row=2, sticky=tk.W) # Adding a Combobox for category. ttk.Label(self.frame_method, text="类别:").grid(column=1, row=1, sticky='E', padx=10) self.cate = tk.StringVar() self.cateCombobox = ttk.Combobox(self.frame_method, width=12, textvariable=self.cate) self.cateCombobox['values'] = ('搞笑', '萌宠', '音乐', '综艺', '动物', '看欧美', '生活') self.cateCombobox.grid(column=2, row=1) self.cateCombobox.current(0) # 设置初始显示值,值为元组['values']的下标 self.cateCombobox.config(state='readonly') # 设为只读模式 # print(self.cateCombobox.grid) # add a user id text ttk.Label(self.frame_method, text="ID:").grid(column=1, row=2, sticky='E', padx=10) self.tk_uid = tk.StringVar() # Adding a Textbox Entry widget ttk.Entry(self.frame_method, width=12, textvariable=self.tk_uid) \ .grid(column=2, row=2, sticky='W') # # add a address bar # ttk.Label(self.frame_method, text="地址:").grid(column=1, row=3, sticky='E', padx=10) # self.addr = tk.StringVar() # # Adding a Textbox Entry widget # ttk.Entry(self.frame_method, width=30, textvariable=self.addr).grid(column=2, row=3, # sticky='W', columnspan=2) # Adding a Button tk.Button(self.frame_method, text="下载", width=15, height=3, command=self._yidian_download_pressed). \ grid(row=1, column=3, rowspan=2, sticky='E') # Using a scrolled Text control to display message. self.yd_scr = scrolledtext.ScrolledText(self.tab_yidian, width=50, height=25, wrap=tk.WORD) self.yd_scr.grid(column=0, row=4, sticky='WE', columnspan=4) self.yd_scr.configure(state='disabled') # ##################################################### # tab 2: watermelone self.frame_method_wm = ttk.LabelFrame(self.tab_watermelon, text='方法设置') self.frame_method_wm.grid(column=0, row=0, padx=4, pady=4) # three methods # # create three Radiobuttons using one variable self._wm_method = tk.IntVar() # Selecting a non-existing index value for radVar self._wm_method.set(0) tk.Radiobutton(self.frame_method_wm, text=values[0], variable=self._wm_method, value=0).grid(column=0, row=1, sticky=tk.W) tk.Radiobutton(self.frame_method_wm, text=values[1], variable=self._wm_method, value=1).grid(column=0, row=2, sticky=tk.W) # self.radio_method_2 = tk.Radiobutton(self.frame_method, text=values[2], variable=self.yidian_method, value=2) # self.radio_method_2.grid(column=0, row=3, sticky=tk.W) # Adding a Combobox for category. ttk.Label(self.frame_method_wm, text="类别:").grid(column=1, row=1, sticky='E', padx=10) self._wm_cate = tk.StringVar() self._tk_cateCombobox_wm = ttk.Combobox(self.frame_method_wm, width=12, textvariable=self._wm_cate) self._tk_cateCombobox_wm['values'] = ('音乐', '新农村', '体育', '爱生活', '美食', '游戏', '社会', '影视', '小视频', '推荐') self._tk_cateCombobox_wm.grid(column=2, row=1) self._tk_cateCombobox_wm.current(0) # 设置初始显示值,值为元组['values']的下标 self._tk_cateCombobox_wm.config(state='readonly') # 设为只读模式 # add a user id text entry. ttk.Label(self.frame_method_wm, text="ID:").grid(column=1, row=2, sticky='E', padx=10) self._tk_str_uid_wm = tk.StringVar() # Adding a Textbox Entry widget ttk.Entry(self.frame_method_wm, width=12, textvariable=self._tk_str_uid_wm) \ .grid(column=2, row=2, sticky='W') # add a address bar # ttk.Label(self.frame_method, text="地址:").grid(column=1, row=3, sticky='E', padx=10) # self.addr = tk.StringVar() # Adding a Textbox Entry widget # ttk.Entry(self.frame_method, width=30, textvariable=self.addr). \ # grid(column=2, row=3, sticky='W', columnspan=2) # Adding a Button tk.Button(self.frame_method_wm, text="下载", width=15, height=3, command=self._wm_download_pressed). \ grid(row=1, column=3, rowspan=2, sticky='E') # Using a scrolled Text control to display message. self._tk_wm_scr = scrolledtext.ScrolledText(self.tab_watermelon, width=50, height=25, wrap=tk.WORD) self._tk_wm_scr.grid(column=0, row=4, sticky='WE', columnspan=4) self._tk_wm_scr.configure(state='disabled') # ##################################################### # Creating a Menu Bar self.menuBar = Menu(self.window) self.window.config(menu=self.menuBar) # Add menu items setting_menu = Menu(self.menuBar, tearoff=0) setting_menu.add_command(label="时长", command=self._menu_setting_time_click) setting_menu.add_separator() self.menuBar.add_cascade(label="设置", menu=setting_menu) # ##################################################### # Change the main windows icon # win.iconbitmap(r'C:\Users\feng\Desktop\研.ico') # Place cursor into name Entry # self.nameEntered.focus() # ====================== # Start GUI # ====================== self.window.mainloop()
progress_bar['value'] = 0 def start_progressbar(): progress_bar.start() def stop_progressbar(): progress_bar.stop() def progressbar_stop_after(wait_ms=1000): win.after(wait_ms, progress_bar.stop) #Sleep funktioniert hier nicht #================================================== #Menüs: #Menubar erzeugen menu_bar= Menu(win) win.config(menu=menu_bar) #Einträge erzeugen + Untermenüpunkte anlegen file_menu = Menu(menu_bar, tearoff=0) #tearoff: entfernt hässlichen Strich (gedacht um ein Menü abzudocken) file_menu.add_command(label='New') #file_menu.add_separator() #Seperator-Linie file_menu.add_command(label='Exit', command=_quit) menu_bar.add_cascade(label='File', menu=file_menu) help_menu = Menu(menu_bar, tearoff=0) menu_bar.add_cascade(label='Help', menu=help_menu) help_menu.add_command(label='About', command=_msgBox) #================================================== #Label a_label = ttk.Label(mighty, text= "Enter a Name:")
login_button = ttk.Button(win, text="Connect", command=site_login) login_button.grid(column=0, row=2, sticky="WE", padx=10, pady=5) quit_button = ttk.Button(win, text="Quit Instance", command=driver_quit) quit_button.grid(column=0, row=3, sticky="WE", padx=10, pady=5) # #exit code def _exit(): driver.quit() win.quit() win.destroy() exit() # #menubar menubar = Menu(win) win.config(menu=menubar) fileMenu = Menu(menubar) menubar.add_cascade(label="File", menu=fileMenu) fileMenu.add_command(label="Exit", command=_exit) for child in AccountDetailsFrame.winfo_children(): child.grid_configure(padx=10, pady=10) # UI execution win.mainloop() # site_login() # input_dialog() # notify_complete("All links successfully saved in file.", link_count(), "Completed") # driver.quit()
def create_file_menu(self): self.file_menu = Menu(self.menu_bar, tearoff=0) self.file_menu.add_command(label="New Game", command=self.on_new_game_menu_clicked) self.menu_bar.add_cascade(label="File", menu=self.file_menu) self.parent.config(menu=self.menu_bar)
def create_about_menu(self): self.about_menu = Menu(self.menu_bar, tearoff=0) self.about_menu.add_command(label="About", command=self.on_about_menu_clicked) self.menu_bar.add_cascade(label="About", menu=self.about_menu) self.parent.config(menu=self.menu_bar)
def createWidgets(self): # Tab Control introduced here -------------------------------------- tabControl = ttk.Notebook(self.win) # Create Tab Control tab1 = ttk.Frame(tabControl) # Create a tab tabControl.add(tab1, text='Tab 1') # Add the tab tab2 = ttk.Frame(tabControl) # Add a second tab tabControl.add(tab2, text='Tab 2') # Make second tab visible tabControl.pack(expand=1, fill="both") # Pack to make visible # ~ Tab Control introduced here ----------------------------------------- # We are creating a container frame to hold all other widgets self.monty = ttk.LabelFrame(tab1, text=' Mighty Python ') self.monty.grid(column=0, row=0, padx=8, pady=4) # Changing our Label ttk.Label(self.monty, text="Enter a name:").grid(column=0, row=0, sticky='W') # Adding a Textbox Entry widget self.name = tk.StringVar() nameEntered = ttk.Entry(self.monty, width=12, textvariable=self.name) nameEntered.grid(column=0, row=1, sticky='W') # Adding a Button self.action = ttk.Button(self.monty, text="Click Me!", command=self.clickMe) self.action.grid(column=2, row=1) ttk.Label(self.monty, text="Choose a number:").grid(column=1, row=0) number = tk.StringVar() numberChosen = ttk.Combobox(self.monty, width=12, textvariable=number) numberChosen['values'] = (1, 2, 4, 42, 100) numberChosen.grid(column=1, row=1) numberChosen.current(0) # Adding a Spinbox widget using a set of values self.spin = Spinbox(self.monty, values=(1, 2, 4, 42, 100), width=5, bd=8, command=self._spin) self.spin.grid(column=0, row=2) # Using a scrolled Text control scrolW = 30; scrolH = 3 self.scr = scrolledtext.ScrolledText(self.monty, width=scrolW, height=scrolH, wrap=tk.WORD) self.scr.grid(column=0, row=3, sticky='WE', columnspan=3) # TODO: ch11 new #------------------------------------------------------------------------- #------------------------------------------------------------------------- # Adding another Button self.action = ttk.Button(self.monty, text="Clear Text", command=self.clearScrol) self.action.grid(column=2, row=2) # Adding more Feature Buttons startRow = 4 for idx in range(12): if idx < 2: col = idx else: col += 1 if not idx % 3: startRow += 1 col = 0 b = ttk.Button(self.monty, text="Feature " + str(idx+1)) b.grid(column=col, row=startRow) # Tab Control 3 ----------------------------------------- tab3 = ttk.Frame(tabControl) # Add a tab tabControl.add(tab3, text='Tab 3') # Make tab visible # We are creating a container frame to hold all other widgets -- Tab3 monty3 = ttk.LabelFrame(tab3, text=' New Features ') monty3.grid(column=0, row=0, padx=8, pady=4) # Adding more Feature Buttons startRow = 4 for idx in range(24): if idx < 2: colIdx = idx col = colIdx else: col += 1 if not idx % 3: startRow += 1 col = 0 b = ttk.Button(monty3, text="Feature " + str(idx+1)) b.grid(column=col, row=startRow) # Add some space around each label for child in monty3.winfo_children(): child.grid_configure(padx=8) #------------------------------------------------------------------------- # TODO: ch11 new end # Tab Control 2 refactoring ----------------------------------------- # We are creating a container frame to hold all other widgets -- Tab2 self.monty2 = ttk.LabelFrame(tab2, text=' Holy Grail ') self.monty2.grid(column=0, row=0, padx=8, pady=4) # Creating three checkbuttons chVarDis = tk.IntVar() check1 = tk.Checkbutton(self.monty2, text="Disabled", variable=chVarDis, state='disabled') check1.select() check1.grid(column=0, row=0, sticky=tk.W) self.chVarUn = tk.IntVar() self.check2 = tk.Checkbutton(self.monty2, text="UnChecked", variable=self.chVarUn) self.check2.deselect() self.check2.grid(column=1, row=0, sticky=tk.W ) self.chVarEn = tk.IntVar() self.check3 = tk.Checkbutton(self.monty2, text="Toggle", variable=self.chVarEn) self.check3.deselect() self.check3.grid(column=2, row=0, sticky=tk.W) # trace the state of the two checkbuttons self.chVarUn.trace('w', lambda unused0, unused1, unused2 : self.checkCallback()) self.chVarEn.trace('w', lambda unused0, unused1, unused2 : self.checkCallback()) # ~ Tab Control 2 refactoring ----------------------------------------- # Radiobutton list colors = ["Blue", "Gold", "Red"] self.radVar = tk.IntVar() # Selecting a non-existing index value for radVar self.radVar.set(99) # Creating all three Radiobutton widgets within one loop for col in range(3): curRad = 'rad' + str(col) curRad = tk.Radiobutton(self.monty2, text=colors[col], variable=self.radVar, value=col, command=self.radCall) curRad.grid(column=col, row=6, sticky=tk.W, columnspan=3) # And now adding tooltips ToolTip(curRad, 'This is a Radiobutton control.') # Create a container to hold labels labelsFrame = ttk.LabelFrame(self.monty2, text=' Labels in a Frame ') labelsFrame.grid(column=0, row=7) # Place labels into the container element - vertically ttk.Label(labelsFrame, text="Label1").grid(column=0, row=0) ttk.Label(labelsFrame, text="Label2").grid(column=0, row=1) # Add some space around each label for child in labelsFrame.winfo_children(): child.grid_configure(padx=8) # Creating a Menu Bar menuBar = Menu(tab1) self.win.config(menu=menuBar) # Add menu items fileMenu = Menu(menuBar, tearoff=0) fileMenu.add_command(label="New") fileMenu.add_separator() fileMenu.add_command(label="Exit", command=self._quit) menuBar.add_cascade(label="File", menu=fileMenu) # Add another Menu to the Menu Bar and an item helpMenu = Menu(menuBar, tearoff=0) helpMenu.add_command(label="About") menuBar.add_cascade(label="Help", menu=helpMenu) # Change the main windows icon self.win.iconbitmap('pyc.ico') # Using tkinter Variable Classes strData = tk.StringVar() strData.set('Hello StringVar') print(strData.get()) # Default tkinter Variable Classes intData = tk.IntVar() print(intData.get()) print(tk.DoubleVar()) print(tk.BooleanVar()) # It is not necessary to create a tk.StringVar() strData = tk.StringVar() strData = self.spin.get() print("Hello " + strData) # Printing the Global works print(GLOBAL_CONST) # call method self.usingGlobal() # Place cursor into name Entry nameEntered.focus() # Add a Tooltip to the Spinbox ToolTip(self.spin, 'This is a Spin control.') # Add Tooltips to more widgets ToolTip(nameEntered, 'This is an Entry control.') ToolTip(self.action, 'This is a Button control.') ToolTip(self.scr, 'This is a ScrolledText control.')
bd=1, activebackground='DarkGray', font=('微软雅黑', 10), command=cancelK) button_a.place(x=90, y=80, width=50, height=30) button_b.place(x=150, y=80, width=50, height=30) #启动消息循环 top2.mainloop() #def _light(): #scr.tag_add(self) #创建菜单栏 menuBar = Menu(top) top.config(menu=menuBar) #添加菜单栏组件 #文件菜单栏 fileMenu = Menu(menuBar, tearoff=0) fileMenu.add_command(label="打开文本文件", command=_open) fileMenu.add_separator() fileMenu.add_command(label="退出文本编辑", command=_quit) menuBar.add_cascade(label="文件", menu=fileMenu) #编辑菜单栏 msgMenu = Menu(menuBar, tearoff=0) msgMenu.add_command(label="查找", command=_seek) msgMenu.add_separator() msgMenu.add_command(label="替换", command=_replace)
def crea_GUI(self): root = self.root #Menús self.menubar = Menu(root, tearoff=0) m_archivo = Menu(self.menubar, tearoff=0) m_archivo.add_command(label='Abrir', command=self.abrir_dataset, accelerator='Ctrl+O') m_archivo.add_separator() m_archivo.add_command(label='Salir', command=self.cerrar_aplicacion) self.menubar.add_cascade(label='Archivo', menu=m_archivo) m_proyecto = Menu(self.menubar, tearoff=0) m_proyecto.add_command(label='Abrir', command=self.abrir_proyecto, state="disabled") m_proyecto.add_separator() m_proyecto.add_checkbutton(label='Clase al final', onvalue=True, offvalue=False, variable=self.clase_al_final) self.menubar.add_cascade(label='Proyecto', menu=m_proyecto) self.m_configuracion = Menu(self.menubar, tearoff=0) self.m_configuracion.add_command( label='Ruta datasets', command=lambda: self.rutas('datasets')) self.m_configuracion.add_command( label='Ruta resultados', command=lambda: self.rutas('resultados')) self.m_configuracion.add_checkbutton(label='Rutas relativas', onvalue=True, offvalue=False, variable=self.rutas_relativas, command=self.cambia_rutas) self.m_configuracion.add_separator() #TODO Revisar self.v_tamanyo_muestra, no la uso # self.v_tamanyo_muestra = StringVar(root, 'Tamaño muestra ({:,})'.\ # format(self._tamanyo_muestra)) self.m_cfg_tamanyo_muestra = \ self.m_configuracion.add_command(label='Tamaño muestra ({:,})'.\ format(self._tamanyo_muestra), command=lambda: self.tamanyo_muestra(\ self._tamanyo_muestra)) self.m_configuracion.add_separator() self.m_configuracion.add_checkbutton(label='Utiliza sha1', onvalue=True, offvalue=False, variable=self.usa_sha1) self.menubar.add_cascade(label='Configuración', menu=self.m_configuracion) m_ver = Menu(self.menubar, tearoff=0) self.v_tipo_dataset = StringVar(self.root, 'Dataset original') m_ver.add_radiobutton(label='Dataset original', value='Dataset original', variable=self.v_tipo_dataset, command=self.muestra_atributos_y_clase) m_ver.add_radiobutton(label='Dataset sin evidencias incompletas', value='Dataset sin evidencias incompletas', variable=self.v_tipo_dataset, command=self.muestra_atributos_y_clase) m_ver.add_radiobutton(label='Dataset sin atributos constantes', value='Dataset sin atributos constantes', variable=self.v_tipo_dataset, command=self.muestra_atributos_y_clase) m_ver.add_radiobutton(label='Catálogo', value='Catálogo', variable=self.v_tipo_dataset, command=self.muestra_atributos_y_clase) m_ver.add_radiobutton(label='Catálogo Robusto', value='Catálogo Robusto', variable=self.v_tipo_dataset, command=self.muestra_atributos_y_clase) m_ver.add_separator() m_ver.add_checkbutton(label='Log del proceso', onvalue=True, offvalue=False, variable=self.mostrar_proceso, state='disabled') self.menubar.add_cascade(label='Ver', menu=m_ver) root.config(menu=self.menubar) #Dataset de clasificación lf_dataset = LabelFrame(root, text='Dataset de Clasificación') lf_dataset.pack(fill='both', expand=True, padx=5, pady=5) Label(lf_dataset, text='Nombre:').grid(row=0, column=0, sticky='e') self.v_nombre_dataset = StringVar(root, '-------') self.l_nombre_dataset = Label(lf_dataset, textvariable=self.v_nombre_dataset) self.l_nombre_dataset.grid(row=0, column=1, sticky='w') Label(lf_dataset, text='Tamaño:').grid(row=0, column=2, sticky='e') self.v_tamanyo_dataset = StringVar(root, '-------') Label(lf_dataset, textvariable=self.v_tamanyo_dataset).grid(row=0, column=3, sticky='w') Label(lf_dataset, text='Ubicación:').grid(row=1, column=0, sticky='e') self.v_ruta_dataset = StringVar(root, '-------------------------') #TODO Expandir en columnas 1-3, puede ser muy larga Label(lf_dataset, textvariable=self.v_ruta_dataset).grid(row=1, column=1, sticky='w', columnspan=3) #Dataset de clasificación / Muestra lf_dataset_muestra = LabelFrame(lf_dataset, text='Muestra') lf_dataset_muestra.grid(row=2, column=0, sticky='nsew', columnspan=4, padx=5, pady=5) self.sb_v_t_muestra = Scrollbar(lf_dataset_muestra) self.sb_v_t_muestra.grid(row=0, column=1, sticky='sn') self.sb_h_t_muestra = Scrollbar(lf_dataset_muestra, orient='horizontal') self.sb_h_t_muestra.grid(row=1, column=0, sticky='ew') self.t_muestra = Text(lf_dataset_muestra, yscrollcommand=self.sb_v_t_muestra.set, xscrollcommand=self.sb_h_t_muestra.set, bd=0, wrap='none', state='disabled', height=8) self.t_muestra.grid(row=0, column=0, sticky='nswe') self.sb_v_t_muestra.config(command=self.t_muestra.yview) self.sb_h_t_muestra.config(command=self.t_muestra.xview) lf_dataset_muestra.rowconfigure(0, weight=1) lf_dataset_muestra.columnconfigure(0, weight=1) lf_dataset.rowconfigure(2, weight=3) lf_dataset.columnconfigure(1, weight=1) lf_dataset.columnconfigure(3, weight=1) #Dataset de clasificación / Evidencias lf_dataset_evidencias = LabelFrame(lf_dataset, text='Evidencias') lf_dataset_evidencias.grid(row=3, column=0, sticky='nsew', padx=5, pady=5) Label(lf_dataset_evidencias, text='Total:').grid(row=0, column=0, sticky='e') self.v_evidencias_total = StringVar(root, '-------') Label(lf_dataset_evidencias, textvariable=self.v_evidencias_total).\ grid(row=0, column=1, sticky='w') Label(lf_dataset_evidencias, text='Completas:').grid(row=1, column=0, sticky='e') self.v_evidencias_completas = StringVar(root, '-------') Label(lf_dataset_evidencias, textvariable=self.v_evidencias_completas).\ grid(row=1, column=1, sticky='w') Label(lf_dataset_evidencias, text='Únicas:').grid(row=2, column=0, sticky='e') self.v_evidencias_catalogo = StringVar(root, '-------') Label(lf_dataset_evidencias, textvariable=self.v_evidencias_catalogo).\ grid(row=2, column=1, sticky='w') Label(lf_dataset_evidencias, text='Robustas:').grid(row=3, column=0, sticky='e') self.v_evidencias_robustas = StringVar(root, '-------') Label(lf_dataset_evidencias, textvariable=self.v_evidencias_robustas).\ grid(row=3, column=1, sticky='w') #Dataset de clasificación / Atributos lf_dataset_clase_y_atributos = LabelFrame(lf_dataset, text='Clase y atributos') lf_dataset_clase_y_atributos.grid(row=3, column=1, sticky='nsew', columnspan=3, padx=5, pady=5) PROPIEDADES_ATRIBUTOS = ('Nombre', 'count', 'unique', 'top', 'freq', 'mean', 'std', 'min', '25%', '50%', '75%', 'max') self.sb_h_tv_clase = Scrollbar(lf_dataset_clase_y_atributos, orient='horizontal') self.sb_h_tv_clase.grid(row=1, column=0, sticky='ew') self.tv_clase = Treeview(lf_dataset_clase_y_atributos, columns=PROPIEDADES_ATRIBUTOS, height=1, xscrollcommand=self.sb_h_tv_clase.set) self.tv_clase.grid(row=0, column=0, sticky='ew') self.sb_h_tv_clase.config(command=self.tv_clase.xview) self.tv_clase.heading("#0", text="#") self.tv_clase.column("#0", minwidth=30, width=40, stretch=False) self.sb_v_tv_atributos = Scrollbar(lf_dataset_clase_y_atributos) self.sb_v_tv_atributos.grid(row=2, column=1, sticky='sn') self.sb_h_tv_atributos = Scrollbar(lf_dataset_clase_y_atributos, orient='horizontal') self.sb_h_tv_atributos.grid(row=3, column=0, sticky='ew') self.tv_atributos = Treeview(lf_dataset_clase_y_atributos, columns=PROPIEDADES_ATRIBUTOS, yscrollcommand=self.sb_v_tv_atributos.set, xscrollcommand=self.sb_h_tv_atributos.set) self.tv_atributos.grid(row=2, column=0, sticky='nsew') self.tv_atributos.bind('<ButtonRelease-1>', self.selectItem) self.sb_v_tv_atributos.config(command=self.tv_atributos.yview) self.sb_h_tv_atributos.config(command=self.tv_atributos.xview) self.tv_atributos.heading("#0", text="#") self.tv_atributos.column("#0", minwidth=30, width=40, stretch=False) for i in PROPIEDADES_ATRIBUTOS: self.tv_clase.heading(i, text=i) self.tv_clase.column(i, minwidth=50, width=50, stretch=False) self.tv_atributos.heading(i, text=i) self.tv_atributos.column(i, minwidth=50, width=50, stretch=False) lf_dataset_clase_y_atributos.rowconfigure(2, weight=1) lf_dataset_clase_y_atributos.columnconfigure(0, weight=1) lf_dataset.rowconfigure(3, weight=1)
def underline(e=None): global current_fontmode current_fontmode = "underline" text.config(font=(current_font, textsize, "underline")) textsize = 13 opened_filename = "" current_font = "Arial" current_fontmode = "normal" root = Tk() root.title("Python Texteditor von Felix") menu = Menu(root) filemenu = Menu(root) root.config(menu=menu) menu.add_cascade(label="File", menu=filemenu) filemenu.add_command(label="Save as...", command=save, accelerator="Ctrl-s") root.bind('<Control-s>', save) filemenu.add_command(label="Open...", command=open_file, accelerator="Ctrl-o") root.bind('<Control-o>', open_file) filemenu.add_separator() filemenu.add_command(label="Copy selection", command=copy, accelerator="Ctrl-c") root.bind('<Control-c>', copy) filemenu.add_command(label="Highlight text", command=highlight_all, accelerator="Ctrl-a")
mBox.showinfo('Datos Generales','Datos incompletos') else: if opcion.get()==1: cad1="Soltero" if opcion.get()==2: cad1="Casado" if opcion.get()==3: cad1="Viudo" cade="\n\nPasatiempos:\n" if opc_1.get()!=0: cade+="Leer " if opc_2.get()!=0: cade+="Ver Peliculas " if opc_3.get()!=0: cade+="Redes Sociales" cade+="\n\nEstado Civil:\n" cade+=cad1+"\n\nObjetivo de la vida:\n"+obj.get() cad="Nombre: "+nombre.get()+"\n\nApellido P: "+apellidop.get()+"\n\nApellido M: "+apellidom.get()+"\n\nDirección: "+direccion.get()+"\n\nColonia: "+colonia.get()+"\n\nCiudad: "+ciudad.get()+"\n\nMunicipio: "+municipio.get() cad+=cade mBox.showinfo('Datos',cad) barra_menu=Menu(ventana) ventana.config(menu=barra_menu) opc_menu=Menu(barra_menu,tearoff=0) opc_menu.add_separator() opc_menu.add_command(label="Imprimir",command=funcion_imprimir) opc_menu.add_separator() opc_menu.add_command(label="Salir",command=funcion_salir) barra_menu.add_cascade(label="Sistemas",menu=opc_menu) opc_menu2=Menu(barra_menu,tearoff=0) opc_menu2.add_separator() opc_menu2.add_command(label="Acerca de",command=funcion_acerca) barra_menu.add_cascade(label="Ayuda",menu=opc_menu2)
def overrideRootMenu(root, flist): """ Replace the Tk root menu by something that is more appropriate for IDLE with an Aqua Tk. """ # The menu that is attached to the Tk root (".") is also used by AquaTk for # all windows that don't specify a menu of their own. The default menubar # contains a number of menus, none of which are appropriate for IDLE. The # Most annoying of those is an 'About Tck/Tk...' menu in the application # menu. # # This function replaces the default menubar by a mostly empty one, it # should only contain the correct application menu and the window menu. # # Due to a (mis-)feature of TkAqua the user will also see an empty Help # menu. from tkinter import Menu from idlelib import mainmenu from idlelib import windows closeItem = mainmenu.menudefs[0][1][-2] # Remove the last 3 items of the file menu: a separator, close window and # quit. Close window will be reinserted just above the save item, where # it should be according to the HIG. Quit is in the application menu. del mainmenu.menudefs[0][1][-3:] mainmenu.menudefs[0][1].insert(6, closeItem) # Remove the 'About' entry from the help menu, it is in the application # menu del mainmenu.menudefs[-1][1][0:2] # Remove the 'Configure Idle' entry from the options menu, it is in the # application menu as 'Preferences' del mainmenu.menudefs[-2][1][0] menubar = Menu(root) root.configure(menu=menubar) menudict = {} menudict['windows'] = menu = Menu(menubar, name='windows', tearoff=0) menubar.add_cascade(label='Window', menu=menu, underline=0) def postwindowsmenu(menu=menu): end = menu.index('end') if end is None: end = -1 if end > 0: menu.delete(0, end) windows.add_windows_to_menu(menu) windows.register_callback(postwindowsmenu) def about_dialog(event=None): "Handle Help 'About IDLE' event." # Synchronize with editor.EditorWindow.about_dialog. from idlelib import help_about help_about.AboutDialog(root, 'About IDLE') def config_dialog(event=None): "Handle Options 'Configure IDLE' event." # Synchronize with editor.EditorWindow.config_dialog. from idlelib import configdialog # Ensure that the root object has an instance_dict attribute, # mirrors code in EditorWindow (although that sets the attribute # on an EditorWindow instance that is then passed as the first # argument to ConfigDialog) root.instance_dict = flist.inversedict configdialog.ConfigDialog(root, 'Settings') def help_dialog(event=None): "Handle Help 'IDLE Help' event." # Synchronize with editor.EditorWindow.help_dialog. from idlelib import help help.show_idlehelp(root) root.bind('<<about-idle>>', about_dialog) root.bind('<<open-config-dialog>>', config_dialog) root.createcommand('::tk::mac::ShowPreferences', config_dialog) if flist: root.bind('<<close-all-windows>>', flist.close_all_callback) # The binding above doesn't reliably work on all versions of Tk # on MacOSX. Adding command definition below does seem to do the # right thing for now. root.createcommand('exit', flist.close_all_callback) if isCarbonTk(): # for Carbon AquaTk, replace the default Tk apple menu menudict['application'] = menu = Menu(menubar, name='apple', tearoff=0) menubar.add_cascade(label='IDLE', menu=menu) mainmenu.menudefs.insert(0, ('application', [ ('About IDLE', '<<about-idle>>'), None, ])) if isCocoaTk(): # replace default About dialog with About IDLE one root.createcommand('tkAboutDialog', about_dialog) # replace default "Help" item in Help menu root.createcommand('::tk::mac::ShowHelp', help_dialog) # remove redundant "IDLE Help" from menu del mainmenu.menudefs[-1][1][0]
def show_popup_menu(event): popup_menu.tk_popup(event.x_root, event.y_root) #ICONS CODE new_File_icon = PhotoImage(file='icons/new_file.gif') open_File_icon = PhotoImage(file='icons/open_file.gif') save_File_icon = PhotoImage(file='icons/save.gif') cut_icon = PhotoImage(file='icons/cut.gif') copy_icon = PhotoImage(file='icons/copy.gif') paste_icon = PhotoImage(file='icons/paste.gif') undo_icon = PhotoImage(file='icons/undo.gif') redo_icon = PhotoImage(file='icons/redo.gif') #FILE MENU OPTIONS menu = Menu(root) root.config(menu=menu) filemenu = Menu(menu, tearoff=0) menu.add_cascade(label='File', menu=filemenu) filemenu.add_command(label='New', command=new_file, accelerator="Ctrl+N", compound='left', image=new_File_icon, underline=0) filemenu.add_command(label='Open', command=open_file, accelerator="Ctrl+O", compound='left', image=open_File_icon, underline=0)
newGameButton = Button(leftFrame2, text="Rejouer", command=playAgain) newGameButton.grid(row=1, column=1, padx=(50, 0)) valueScore = StringVar() scoreMax = Label(leftFrame, textvariable=valueScore, bg='#9C4044', fg='#0046FF') scoreMax.grid(row=6, columnspan=2, pady=(10, 0)) #on importe toutes les images image1 = PhotoImage(master=window, file='image/mimage1.gif') image2 = PhotoImage(master=window, file='image/mimage2.gif') image3 = PhotoImage(master=window, file='image/mimage3.gif') image4 = PhotoImage(master=window, file='image/mimage4.gif') image5 = PhotoImage(master=window, file='image/mimage5.gif') image6 = PhotoImage(master=window, file='image/mimage6.gif') image7 = PhotoImage(master=window, file='image/mimage7.gif') image8 = PhotoImage(master=window, file='image/mimage8.gif') #initialisation du canvas avec une image vide item = Canevas.create_image(250, 250, image=image8) menuBar = Menu(window) menuFile = Menu(menuBar, tearoff=0) menuFile.add_command(label="Rejouer", command=playAgain) menuFile.add_command(label="Quitter", command=window.quit) menuBar.add_cascade(label="Fenêtre", menu=menuFile) window.config(menu=menuBar) window.mainloop()
def __init__(self): self.liveCategories = [] self.programState = None self.dataBase = usersData() self.load() self.loggedIn = False self.currentUser = None self.logIn() self.cGUIlist = [] if self.loggedIn == True: self.win = tk.Tk() menubar = Menu(self.win) self.win.config(menu=menubar) fileMenu = Menu(menubar) def newCat(): #clear all widgets?? tvar1 = tk.StringVar() catEnt = tk.Entry(textvariable=tvar1) def createCat(): newCatName = tvar1.get() newCat = category(newCatName) self.currentUser.categories.append(newCat) print('New category Object("' + newCatName + '") created.') catEnt.delete(0, 'end') catButt = tk.Button(text='Create', command=createCat) catEnt.grid(row=0, column=0) catButt.grid(column=1, row=0) def quit(): self.win.quit() self.win.destroy() exit() def workflow(): self.liveCategories = [] now = datetime.datetime.now() print('---Creating liveCat list--') for q in self.currentUser.categories: self.liveCategories.append(str(q.name)) print('Active liveCategories list:') for r in self.liveCategories: print(r) index = 0 for x in self.liveCategories: print('----' + str(x) + ' checking for today\'s results.' + '---') for z in self.currentUser.results: if x == z.name and z.year == now.year and z.day == now.day and z.month == now.month: print('Result found for today:' + x + ' ' + z.name) self.liveCategories.pop(index) index = index + 1 index = 1 #interleaving for w in self.liveCategories: print(str(index) + '. ' + w) index = index + 1 inNum = input('Input number to complete.') scoreNum = input( 'Okay ' + self.liveCategories[int(inNum) - 1] + ' is being completed. Input integer score out of 100.') comment = input('Input comments/reflection.') catComplete = categoryComplete( self.liveCategories[int(inNum) - 1], comment, scoreNum) self.currentUser.results.append(catComplete) self.save() workflow() fileMenu.add_command(label='Create New Category', command=newCat) fileMenu.add_command(label='Workflow Mode', command=workflow) fileMenu.add_command(label='Exit', command=quit) menubar.add_cascade(label="File", menu=fileMenu) self.win.mainloop()
bg='#FFFF00') canvas.grid(row=i, column=i) # ---------------Tab3控件介绍------------------# # ----------------菜单栏介绍-------------------# # Exit GUI cleanly def _quit(): win.quit() win.destroy() exit() # Creating a Menu Bar menuBar = Menu(win) win.config(menu=menuBar) # Add menu items fileMenu = Menu(menuBar, tearoff=0) fileMenu.add_command(label="新建") fileMenu.add_separator() fileMenu.add_command(label="退出", command=_quit) menuBar.add_cascade(label="文件", menu=fileMenu) # Display a Message Box def _msgBox1(): mBox.showinfo('Python Message Info Box', '通知:程序运行正常!')
n += 1 from os import path from tkinter import filedialog Label(window, text="Example of file dialog:").grid(column=0,row=n) #file = filedialog.askopenfilename() #file = filedialog.askopenfilename(initialdir= path.dirname(__file__)) #file.grid(column = 1, row = n) # menu from tkinter import Menu menu = Menu(window) new_item = Menu(menu) sav_item = Menu(menu) new_item.add_command(label='New') sav_item.add_command(label="save_as_png") sav_item.add_separator() sav_item.add_command(label="save_as_jpg") menu.add_cascade(label='File', menu=new_item) menu.add_cascade(label="Save", menu=sav_item) window.config(menu=menu) ''' # notebook
window.title("右键弹出菜单") def callback(): print("回调") # 创建窗口 def createWindow(): w = Toplevel() w.title("新建窗口") # 绑定右键事件,在窗口的任意位置都可以右键弹出菜单 w.bind("<ButtonPress-2>", popup) menuBar = Menu(window) # 菜单栏 text_menu = Menu(menuBar) # 创建菜单,作为下拉菜单列表 menuBar.add_cascade(label="文本", menu=text_menu, command=callback) # 作为下拉菜单的标题 # 二级菜单 text_menu.add_command(label="复制", command=callback) text_menu.add_command(label="粘贴", command=callback) text_menu.add_command(label="撤销", command=callback) text_menu.add_separator() text_menu.add_command(label="重置", command=callback) text_menu.add_command(label="新建窗口", command=createWindow) # 一级菜单,直接放在菜单栏上,窗口菜单栏上不会生效 menuBar.add_separator() menuBar.add_command(label="重置2", command=callback) # 窗口菜单栏不现实
def add_admin_menu(self): menu = Menu(self.menubar, tearoff=0) menu.add_command(label="Refresh All Log Meta", command=refresh_all_log_meta) self.menubar.add_cascade(label="Admin", menu=menu)
def __init__(self): self.window = Tk() self.window.title("自动化交易系统-同花顺") # 左上角图标 #self.window.iconbitmap('e:\ico.ico') self.window.resizable(0, 0) frame1 = Frame(self.window) frame1.pack(padx=10, pady=10) Label(frame1, text="股票代码", width=8, justify=CENTER).grid(row=1, column=1, padx=5, pady=5) Label(frame1, text="股票名称", width=8, justify=CENTER).grid(row=1, column=2, padx=5, pady=5) Label(frame1, text="实时价格", width=8, justify=CENTER).grid(row=1, column=3, padx=5, pady=5) Label(frame1, text="关系", width=4, justify=CENTER).grid(row=1, column=4, padx=5, pady=5) Label(frame1, text="设定价格", width=8, justify=CENTER).grid(row=1, column=5, padx=5, pady=5) Label(frame1, text="方向", width=4, justify=CENTER).grid(row=1, column=6, padx=5, pady=5) Label(frame1, text="数量", width=8, justify=CENTER).grid(row=1, column=7, padx=5, pady=5) Label(frame1, text="时间可选", width=8, justify=CENTER).grid(row=1, column=8, padx=5, pady=5) Label(frame1, text="委托", width=6, justify=CENTER).grid(row=1, column=9, padx=5, pady=5) Label(frame1, text="成交", width=6, justify=CENTER).grid(row=1, column=10, padx=5, pady=5) self.rows = NUM_OF_STOCKS self.cols = 10 self.variable = [] for row in range(self.rows): self.variable.append([]) for col in range(self.cols): self.variable[row].append(StringVar()) for row in range(self.rows): Entry(frame1, textvariable=self.variable[row][0], width=8).grid(row=row + 2, column=1, padx=5, pady=5) Entry(frame1, textvariable=self.variable[row][1], state=DISABLED, width=8).grid(row=row + 2, column=2, padx=5, pady=5) Entry(frame1, textvariable=self.variable[row][2], state=DISABLED, justify=RIGHT, width=8).grid(row=row + 2, column=3, padx=5, pady=5) Combobox(frame1, values=('<', '>'), textvariable=self.variable[row][3], width=2).grid(row=row + 2, column=4, padx=5, pady=5) Spinbox(frame1, from_=0, to=999, textvariable=self.variable[row][4], justify=RIGHT, increment=0.01, width=6).grid(row=row + 2, column=5, padx=5, pady=5) Combobox(frame1, values=('B', 'S'), textvariable=self.variable[row][5], width=2).grid(row=row + 2, column=6, padx=5, pady=5) Spinbox(frame1, from_=0, to=10000, textvariable=self.variable[row][6], justify=RIGHT, increment=100, width=6).grid(row=row + 2, column=7, padx=5, pady=5) Entry(frame1, textvariable=self.variable[row][7], width=8).grid(row=row + 2, column=8, padx=5, pady=5) Entry(frame1, textvariable=self.variable[row][8], state=DISABLED, justify=CENTER, width=6).grid(row=row + 2, column=9, padx=5, pady=5) Entry(frame1, textvariable=self.variable[row][9], state=DISABLED, justify=RIGHT, width=6).grid(row=row + 2, column=10, padx=5, pady=5) frame3 = Frame(self.window) frame3.pack(padx=10, pady=10) # 创建菜单功能 self.menuBar = Menu(self.window) self.window.config(menu=self.menuBar) # tearoff=0 代表将菜单项最上面的一条虚线去掉,默认是存在的 self.fileMenu = Menu(self.menuBar, tearoff=0) # 创建一个名为“帮助”的菜单项 self.menuBar.add_cascade(label="帮助", menu=self.fileMenu) # 在“帮助”项下添加一个名为“关于”的选项 self.fileMenu.add_command(label="关于", command=self.about) # 增加一条横线 self.fileMenu.add_separator() # 在“帮助”项下添加一个名为“退出”的选项,并绑定执行函数 self.fileMenu.add_command(label="退出", command=self.close) # 增加第二个导航栏 # self.helpMenu = Menu(self.menuBar,tearoff=0) # self.menuBar.add_cascade(label="Help", menu=self.helpMenu) # self.helpMenu.add_command(label="About") self.start_bt = Button(frame3, text="开始", command=self.start) self.start_bt.pack(side=LEFT) self.set_bt = Button(frame3, text='重置买卖', command=self.setFlags) self.set_bt.pack(side=LEFT) Button(frame3, text="历史记录", command=self.displayHisRecords).pack(side=LEFT) Button(frame3, text='保存', command=self.save).pack(side=LEFT) self.load_bt = Button(frame3, text='载入', command=self.load) self.load_bt.pack(side=LEFT) self.window.protocol(name="WM_DELETE_WINDOW", func=self.close) self.window.after(100, self.updateControls) self.window.mainloop()
ttk.Label(labelsFrame, text="Label3").grid(column=0, row=2) # Add some space around each label for child in labelsFrame.winfo_children(): child.grid_configure(padx=8, pady=1) # Exit GUI cleanly def _quit(): win.quit() win.destroy() exit() # Creating a Menu Bar menuBar = Menu(win) win.config(menu=menuBar) # Add menu items fileMenu = Menu(menuBar, tearoff=0) fileMenu.add_command(label="New") fileMenu.add_separator() fileMenu.add_command(label="Exit", command=_quit) menuBar.add_cascade(label="File", menu=fileMenu) # Add another Menu to the Menu Bar and an item helpMenu = Menu(menuBar, tearoff=0) helpMenu.add_command(label="About") menuBar.add_cascade(label="Help", menu=helpMenu) # Place cursor into name Entry
def create_top_menu(self): self.menu_bar = Menu(self.parent) self.create_file_menu() self.create_edit_menu() self.create_about_menu()
def __init__(self): """ Cette fenêtre contient la configuration requise pour débuter le jeu PyMafia L'usager doit remplir les données requises avant de pouvoir débuter le jeu """ super().__init__() self.title("PyMafia - Débuter une partie") self.resizable(0, 0) self.framesuperieur = Frame(self) self.framesuperieur.grid(row=0, column=0, columnspan=3) self.framesuperieur['highlightthickness'] = 0 self.framesuperieur['highlightbackground'] = 'black' self.framechoix = Frame(self) self.framechoix.grid(row=1, column=0, columnspan=3) self.framechoix['highlightthickness'] = 0 self.framechoix['highlightbackground'] = 'black' self.frameinferieur = Frame(self) self.frameinferieur.grid(row=2, column=0, columnspan=3) self.frameinferieur['highlightthickness'] = 0 self.frameinferieur['highlightbackground'] = 'black' debuttxt = "Bienvenue à PyMafia, pour débuter une partie, veuillez indiquer le nombre de joueurs: " self.label = Label(self.framesuperieur, text=debuttxt, relief=FLAT) self.label.grid(row=0, column=0, padx=10, pady=10) # Création du DropDown choix_nb_joueurs = ["2", "3", "4"] nb_joueur = StringVar(self) nb_joueur.set(choix_nb_joueurs[0]) radiobuttons = list() self.totalJoueurs = OptionMenu( self.framesuperieur, nb_joueur, *choix_nb_joueurs, command=lambda event: self.changement_dropdown( radiobuttons, nb_joueur)) self.totalJoueurs.grid(row=0, column=1, padx=10, pady=10) # Fin DropDown self.labelChoixHumainOrdinateur = Label( self.framechoix, text="Veuillez choisir le type de joueur:", relief=FLAT, justify=LEFT, state=DISABLED, anchor="w") self.labelChoixHumainOrdinateur.grid(row=1, column=0, padx=10, pady=10) self.debuterPartie = Button(self.frameinferieur, text="Let's do this baby!") self.joueurVar = self.créer_boutons_radios(radiobuttons, int(nb_joueur.get())) self.debuterPartie.bind( "<ButtonRelease-1>", lambda event: self.commencer_partie(nb_joueur, self.joueurVar)) self.debuterPartie.grid(row=int(nb_joueur.get()) + 2, column=1, padx=10, pady=10) intvar = IntVar() self.menu = Menu(self) self.optionMenu = OptionMenu(self, intvar, 3, 4, 5, 6) self.premier_menu = Menu(self.menu, tearoff=0) self.premier_menu.add_command(label='Règlements', command=self.afficher_reglements) self.premier_menu.add_separator() self.premier_menu.add_command(label='Quitter', command=self.validation_de_sortie) self.menu.add_cascade(label='Fichier', menu=self.premier_menu) self.config(menu=self.menu)
def create_edit_menu(self): self.edit_menu = Menu(self.menu_bar, tearoff=0) self.edit_menu.add_command(label="Preferences", command=self.on_preference_menu_clicked) self.menu_bar.add_cascade(label="Edit", menu=self.edit_menu) self.parent.config(menu=self.menu_bar)
def __init__(self): #cambiando enconde sys.stdin = io.TextIOWrapper(sys.stdin.detach(), encoding='latin-1') #END variables utilizadas durante la ejecución self.window = Tk() #propiedades de la ventana self.window.title("TytusDB") self.window.geometry("815x950") self.window.configure(bg = "#3b5971") self.window.resizable(False, False) #START MENU BAR self.menuBar = Menu(self.window) self.menuBar.add_cascade(label = "Abrir CSV", command = self.abrirArchivo) self.menuBar.add_cascade(label = "Reportes") self.menuBar.add_cascade(label = "Salir", command = self.salir) self.window.config(menu = self.menuBar) #END MENU BAR #titulo self.titulo = Label(self.window, text = "TYTUS DB", font = ("Arial Bold", 25), fg="#a48f60") self.titulo.place(x = 320, y = 5) self.titulo.configure(bg = "#3b5971") #loadCSV() self.loadCSV = Label(self.window, text = "loadCSV", font = ("Arial"), fg="#ffffff") self.loadCSV.place(x = 35, y = 75) self.loadCSV.configure(bg = "#3b5971") self.e1LoadCSV = Entry(self.window) self.e1LoadCSV.place(x=170, y=78) self.e1LoadCSV.configure(bg = "#f2f2f2") self.e2LoadCSV = Entry(self.window) self.e2LoadCSV.place(x=320, y=78) self.e2LoadCSV.configure(bg = "#f2f2f2") self.e3LoadCSV = Entry(self.window) self.e3LoadCSV.place(x=470, y=78) self.e3LoadCSV.configure(bg = "#f2f2f2") self.btnloadCSV = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.loadCSV(self.e1LoadCSV.get(), self.e2LoadCSV.get(), self.e3LoadCSV.get())) self.btnloadCSV.place(x=620, y = 75) #createTable() self.createTable = Label(self.window, text = "createTable", font = ("Arial"), fg="#ffffff") self.createTable.place(x = 35, y = 145) self.createTable.configure(bg = "#3b5971") self.e1createTable = Entry(self.window) self.e1createTable.place(x=170, y=148) self.e1createTable.configure(bg = "#f2f2f2") self.e2createTable = Entry(self.window) self.e2createTable.place(x=320, y=148) self.e2createTable.configure(bg = "#f2f2f2") self.e3createTable= Entry(self.window) self.e3createTable.place(x=470, y=148) self.e3createTable.configure(bg = "#f2f2f2") self.btncreateTable = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.createTable(self.e1createTable.get(), self.e2createTable.get(), self.e3createTable.get())) self.btncreateTable.place(x=620, y = 145) #showTables() self.showTables = Label(self.window, text = "showTables", font = ("Arial"), fg="#ffffff") self.showTables.place(x = 35, y = 180) self.showTables.configure(bg = "#3b5971") self.e1showTables = Entry(self.window) self.e1showTables.place(x=170, y=183) self.e1showTables.configure(bg = "#f2f2f2") self.btnshowTables = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : print(tytus.showTables(self.e1showTables.get()))) self.btnshowTables.place(x=620, y = 180) #alterTable() self.alterTable = Label(self.window, text = "alterTable", font = ("Arial"), fg="#ffffff") self.alterTable.place(x = 35, y = 215) self.alterTable.configure(bg = "#3b5971") self.e1alterTable = Entry(self.window) self.e1alterTable.place(x=170, y=218) self.e1alterTable.configure(bg = "#f2f2f2") self.e2alterTable = Entry(self.window) self.e2alterTable.place(x=320, y=218) self.e2alterTable.configure(bg = "#f2f2f2") self.e3alterTable= Entry(self.window) self.e3alterTable.place(x=470, y=218) self.e3alterTable.configure(bg = "#f2f2f2") self.btnalterTable = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.alterTable(self.e1alterTable.get(), self.e2alterTable.get(), self.e3alterTable.get())) self.btnalterTable.place(x=620, y = 217) #dropTable() self.dropTable = Label(self.window, text = "dropTable", font = ("Arial"), fg="#ffffff") self.dropTable.place(x = 35, y = 250) self.dropTable.configure(bg = "#3b5971") self.e1dropTable = Entry(self.window) self.e1dropTable.place(x=170, y=253) self.e1dropTable.configure(bg = "#f2f2f2") self.e2dropTable = Entry(self.window) self.e2dropTable.place(x=320, y=253) self.e2dropTable.configure(bg = "#f2f2f2") self.btndropTable = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda: tytus.dropTable(self.e1dropTable.get(), self.e2dropTable.get())) self.btndropTable.place(x=620, y = 250) #alterAddPK() self.alterAddPK = Label(self.window, text = "alterAddPK", font = ("Arial"), fg="#ffffff") self.alterAddPK.place(x = 35, y = 285) self.alterAddPK.configure(bg = "#3b5971") self.e1alterAddPK = Entry(self.window) self.e1alterAddPK.place(x=170, y=288) self.e1alterAddPK.configure(bg = "#f2f2f2") self.e2alterAddPK = Entry(self.window) self.e2alterAddPK.place(x=320, y=288) self.e2alterAddPK.configure(bg = "#f2f2f2") self.e3alterAddPK = Entry(self.window) self.e3alterAddPK.place(x=470, y=288) self.e3alterAddPK.configure(bg = "#f2f2f2") self.btnalterAddPK = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.alterAddPK(self.e1alterAddPK.get(), self.e2alterAddPK.get(), self.e3alterAddPK.get())) self.btnalterAddPK.place(x=620, y = 285) #alterDropPK() self.alterDropPK = Label(self.window, text = "alterDrop", font = ("Arial"), fg="#ffffff") self.alterDropPK.place(x = 35, y = 320) self.alterDropPK.configure(bg = "#3b5971") self.e1alterDropPK = Entry(self.window) self.e1alterDropPK.place(x=170, y=323) self.e1alterDropPK.configure(bg = "#f2f2f2") self.e2alterDropPK = Entry(self.window) self.e2alterDropPK.place(x=320, y=323) self.e2alterDropPK.configure(bg = "#f2f2f2") self.btnalterDropPK = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.alterDropPk(self.e1alterDropPK.get(), self.e2alterDropPK.get())) self.btnalterDropPK.place(x=620, y = 320) #extractTable() self.extractTable = Label(self.window, text = "extractTable", font = ("Arial"), fg="#ffffff") self.extractTable.place(x = 35, y = 355) self.extractTable.configure(bg = "#3b5971") self.e1extractTable = Entry(self.window) self.e1extractTable.place(x=170, y=358) self.e1extractTable.configure(bg = "#f2f2f2") self.e2extractTable = Entry(self.window) self.e2extractTable.place(x=320, y=358) self.e2extractTable.configure(bg = "#f2f2f2") self.btnextractTable = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.extractTable(self.e1extractTable.get(), self.e2extractTable.get())) self.btnextractTable.place(x=620, y = 355) #insert() self.insert = Label(self.window, text = "insert", font = ("Arial"), fg="#ffffff") self.insert.place(x = 35, y = 390) self.insert.configure(bg = "#3b5971") self.e1insert = Entry(self.window) self.e1insert.place(x=170, y=393) self.e1insert.configure(bg = "#f2f2f2") self.e2insert = Entry(self.window) self.e2insert.place(x=320, y=393) self.e2insert.configure(bg = "#f2f2f2") self.e3insert= Entry(self.window) self.e3insert.place(x=470, y=393) self.e3insert.configure(bg = "#f2f2f2") self.btninsert = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.insert(self.e1insert.get(), self.e2insert.get(), self.e3insert.get())) self.btninsert.place(x=620, y = 390) #update() self.update = Label(self.window, text = "update", font = ("Arial"), fg="#ffffff") self.update.place(x = 35, y = 425) self.update.configure(bg = "#3b5971") self.e1update = Entry(self.window) self.e1update.place(x=170, y=428) self.e1update.configure(bg = "#f2f2f2") self.e2update = Entry(self.window) self.e2update.place(x=320, y=428) self.e2update.configure(bg = "#f2f2f2") self.e3update= Entry(self.window) self.e3update.place(x=470, y=428) self.e3update.configure(bg = "#f2f2f2") self.e4update = Entry(self.window) self.e4update.place(x=170, y=463) self.e4update.configure(bg = "#f2f2f2") self.btnupdate = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda: tytus.update(self.e1update.get(), self.e2update.get(), self.e3update.get(), self.e4update.get())) self.btnupdate.place(x=620, y = 425) #delete() self.delete = Label(self.window, text = "delete", font = ("Arial"), fg="#ffffff") self.delete.place(x = 35, y = 495) self.delete.configure(bg = "#3b5971") self.e1delete = Entry(self.window) self.e1delete.place(x=170, y=498) self.e1delete.configure(bg = "#f2f2f2") self.e2delete = Entry(self.window) self.e2delete.place(x=320, y=498) self.e2delete.configure(bg = "#f2f2f2") self.e3delete = Entry(self.window) self.e3delete.place(x=470, y=498) self.e3delete.configure(bg = "#f2f2f2") self.btndelete = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda: tytus.delete(self.e1delete.get(), self.e2delete.get(), self.e3delete.get())) self.btndelete.place(x=620, y = 495) #truncate() self.truncate = Label(self.window, text = "truncate", font = ("Arial"), fg="#ffffff") self.truncate.place(x = 35, y = 530) self.truncate.configure(bg = "#3b5971") self.e1truncate = Entry(self.window) self.e1truncate.place(x=170, y=533) self.e1truncate.configure(bg = "#f2f2f2") self.e2truncate = Entry(self.window) self.e2truncate.place(x=320, y=533) self.e2truncate.configure(bg = "#f2f2f2") self.btntruncate = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.truncate(self.e1truncate.get(), self.e2truncate.get())) self.btntruncate.place(x=620, y = 530) #extractRow self.extractRow = Label(self.window, text = "extractRow", font = ("Arial"), fg="#ffffff") self.extractRow.place(x = 35, y = 565) self.extractRow.configure(bg = "#3b5971") self.e1extractRow = Entry(self.window) self.e1extractRow.place(x=170, y=568) self.e1extractRow.configure(bg = "#f2f2f2") self.e2extractRow = Entry(self.window) self.e2extractRow.place(x=320, y=568) self.e2extractRow.configure(bg = "#f2f2f2") self.e3extractRow= Entry(self.window) self.e3extractRow.place(x=470, y=568) self.e3extractRow.configure(bg = "#f2f2f2") self.btnextractRow = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.extractRow(self.e1extractRow.get(), self.e2extractRow.get(), self.e3extractRow.get())) self.btnextractRow.place(x=620, y = 565) #createDatabase() self.createDatabase = Label(self.window, text = "createDatabase", font = ("Arial"), fg="#ffffff") self.createDatabase.place(x = 35, y = 600) self.createDatabase.configure(bg = "#3b5971") self.e1createDatabase = Entry(self.window) self.e1createDatabase.place(x=170, y=603) self.e1createDatabase.configure(bg = "#f2f2f2") self.btncreateDatabase = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff" , command= lambda: tytus.createDatabase(self.e1createDatabase.get())) self.btncreateDatabase.place(x=620, y = 600) #showDatabases() self.showDatabases = Label(self.window, text = "showDatabases", font = ("Arial"), fg="#ffffff") self.showDatabases.place(x = 35, y = 635) self.showDatabases.configure(bg = "#3b5971") self.btnshowDatabases = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : print(tytus.showDatabases())) self.btnshowDatabases.place(x=620, y = 635) #alterDatabase() self.alterDatabases = Label(self.window, text = "alterDatabases", font = ("Arial"), fg="#ffffff") self.alterDatabases.place(x = 35, y = 670) self.alterDatabases.configure(bg = "#3b5971") e1alterDatabases = self.e1alterDatabases = Entry(self.window) self.e1alterDatabases.place(x=170, y=673) self.e1alterDatabases.configure(bg = "#f2f2f2") e2alterDatabases = self.e2alterDatabases = Entry(self.window) self.e2alterDatabases.place(x=320, y=673) self.e2alterDatabases.configure(bg = "#f2f2f2") self.btnalterDatabase = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda : tytus.alterDatabase(e1alterDatabases.get(), e2alterDatabases.get())) self.btnalterDatabase.place(x=620, y = 670) #dropDatabase() self.dropDatabase = Label(self.window, text = "dropDatabase", font = ("Arial"), fg="#ffffff") self.dropDatabase.place(x = 35, y = 705) self.dropDatabase.configure(bg = "#3b5971") self.e1dropDatabase = Entry(self.window) self.e1dropDatabase.place(x=170, y=708) self.e1dropDatabase.configure(bg = "#f2f2f2") self.btndropDatabase = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda: print(tytus.dropDatabase(self.e1dropDatabase.get()))) self.btndropDatabase.place(x=620, y = 705) #alterAddColumn() self.alterAddColumn = Label(self.window, text = "alterAddColumn", font = ("Arial"), fg="#ffffff") self.alterAddColumn.place(x = 35, y = 740) self.alterAddColumn.configure(bg = "#3b5971") self.e1alterAddColumn = Entry(self.window) self.e1alterAddColumn.place(x=170, y=743) self.e1alterAddColumn.configure(bg = "#f2f2f2") self.e2alterAddColumn = Entry(self.window) self.e2alterAddColumn.place(x=320, y=743) self.e2alterAddColumn.configure(bg = "#f2f2f2") self.e3alterAddColumn = Entry(self.window) self.e3alterAddColumn.place(x=470, y=743) self.e3alterAddColumn.configure(bg = "#f2f2f2") self.btnalterAddColumn = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command= lambda: tytus.alterAddColumn(self.e1alterAddColumn.get(), self.e2alterAddColumn.get(), self.e3alterAddColumn.get())) self.btnalterAddColumn.place(x=620, y = 740) #alterDropColumn self.alterDropColumn = Label(self.window, text = "alterDropColumn", font = ("Arial"), fg="#ffffff") self.alterDropColumn.place(x = 35, y = 775) self.alterDropColumn.configure(bg = "#3b5971") self.e1alterDropColumn = Entry(self.window) self.e1alterDropColumn.place(x=170, y=778) self.e1alterDropColumn.configure(bg = "#f2f2f2") self.e2alterDropColumn = Entry(self.window) self.e2alterDropColumn.place(x=320, y=778) self.e2alterDropColumn.configure(bg = "#f2f2f2") self.e3alterDropColumn = Entry(self.window) self.e3alterDropColumn.place(x=470, y=778) self.e3alterDropColumn.configure(bg = "#f2f2f2") self.btnalterDropColumn = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command= lambda: tytus.alterDropColumn(self.e1alterDropColumn.get(), self.e2alterDropColumn.get(), self.e3alterDropColumn.get())) self.btnalterDropColumn.place(x=620, y = 775) #extractRangeTable() self.extractRangeTable = Label(self.window, text = "extractRangeTable", font = ("Arial"), fg="#ffffff") self.extractRangeTable.place(x = 35, y = 810) self.extractRangeTable.configure(bg = "#3b5971") self.e1extractRangeTable = Entry(self.window) self.e1extractRangeTable.place(x=170, y=813) self.e1extractRangeTable.configure(bg = "#f2f2f2") self.e2extractRangeTable = Entry(self.window) self.e2extractRangeTable.place(x=320, y=813) self.e2extractRangeTable.configure(bg = "#f2f2f2") self.e3extractRangeTable = Entry(self.window) self.e3extractRangeTable.place(x=470, y=813 ) self.e3extractRangeTable.configure(bg = "#f2f2f2") self.e4extractRangeTable = Entry(self.window) self.e4extractRangeTable.place(x=170, y=848) self.e4extractRangeTable.configure(bg = "#f2f2f2") self.btnextractRangeTable = Button(self.window, text="Ejecutar", width=20, bg = "#a48f60", fg="#ffffff", command=lambda: tytus.extractRangeTable(self.e1extractRangeTable.get(), self.e2extractRangeTable.get(), self.e3extractRangeTable.get(), self.e4extractRangeTable.get())) self.btnextractRangeTable.place(x=620, y = 845) #lanza la ventana (la muestra en pantalla) self.window.mainloop()
from tkinter import * from tkinter import Menu import tkinter as tk from tkinter import ttk from tkinter.filedialog import askopenfile from tkinter.filedialog import askopenfilename # Imports the other 2 scripts to be used import PCA import Admix # Setting up tkinter and the main window mainWindow = tk.Tk() mainWindow.geometry("800x300") mainWindow.title("Genesis V2.0") menu = Menu(mainWindow) frame = tk.Frame(mainWindow) frame.pack() #-------------------------------------------------------------------------- # Global variables used throughout the UI columnAdmix = 0 columnPCAEvec1 = 0 columnPCAEvec2 = 0 columnPCAEvec3 = 0 columnPCAPheno = 0 PCAData = "" PCAPheno = ""
def create_widgets(self): tabControl = ttk.Notebook(self.win) # Create Tab Control tab1 = ttk.Frame(tabControl) # Create a tab tabControl.add(tab1, text='Tab 1') # Add the tab tab2 = ttk.Frame(tabControl) # Add a second tab tabControl.add(tab2, text='Tab 2') # Make second tab visible tabControl.pack(expand=1, fill="both") # Pack to make visible # LabelFrame using tab1 as the parent mighty = ttk.LabelFrame(tab1, text=' Mighty Python ') mighty.grid(column=0, row=0, padx=8, pady=4) # Modify adding a Label using mighty as the parent instead of win a_label = ttk.Label(mighty, text="Enter a name:") a_label.grid(column=0, row=0, sticky='W') # Adding a Textbox Entry widget self.name = tk.StringVar() self.name_entered = ttk.Entry(mighty, width=24, textvariable=self.name) self.name_entered.grid(column=0, row=1, sticky='W') # Adding a Button self.action = ttk.Button(mighty, text="Click Me!", command=self.click_me) self.action.grid(column=2, row=1) ttk.Label(mighty, text="Choose a number:").grid(column=1, row=0) number = tk.StringVar() self.number_chosen = ttk.Combobox(mighty, width=14, textvariable=number, state='readonly') self.number_chosen['values'] = (1, 2, 4, 42, 100) self.number_chosen.grid(column=1, row=1) self.number_chosen.current(0) # Adding a Spinbox widget self.spin = Spinbox(mighty, values=(1, 2, 4, 42, 100), width=5, bd=9, command=self._spin) # using range self.spin.grid(column=0, row=2, sticky='W') # align left # Using a scrolled Text control scrol_w = 40 scrol_h = 10 # increase sizes self.scrol = scrolledtext.ScrolledText(mighty, width=scrol_w, height=scrol_h, wrap=tk.WORD) self.scrol.grid(column=0, row=3, sticky='WE', columnspan=3) for child in mighty.winfo_children(): # add spacing to align widgets within tabs child.grid_configure(padx=4, pady=2) # ===================================================================================== # Tab Control 2 ---------------------------------------------------------------------- self.mighty2 = ttk.LabelFrame(tab2, text=' The Snake ') self.mighty2.grid(column=0, row=0, padx=8, pady=4) # Creating three checkbuttons chVarDis = tk.IntVar() check1 = tk.Checkbutton(self.mighty2, text="Disabled", variable=chVarDis, state='disabled') check1.select() check1.grid(column=0, row=0, sticky=tk.W) chVarUn = tk.IntVar() check2 = tk.Checkbutton(self.mighty2, text="UnChecked", variable=chVarUn) check2.deselect() check2.grid(column=1, row=0, sticky=tk.W) chVarEn = tk.IntVar() check3 = tk.Checkbutton(self.mighty2, text="Enabled", variable=chVarEn) check3.deselect() check3.grid(column=2, row=0, sticky=tk.W) # trace the state of the two checkbuttons chVarUn.trace('w', lambda unused0, unused1, unused2: self.checkCallback()) chVarEn.trace('w', lambda unused0, unused1, unused2: self.checkCallback()) # First, we change our Radiobutton global variables into a list colors = ["Blue", "Gold", "Red"] # create three Radiobuttons using one variable self.radVar = tk.IntVar() # Next we are selecting a non-existing index value for radVar self.radVar.set(99) # Now we are creating all three Radiobutton widgets within one loop for col in range(3): curRad = tk.Radiobutton(self.mighty2, text=colors[col], variable=self.radVar, value=col, command=self.radCall) curRad.grid(column=col, row=1, sticky=tk.W) # row=6 # And now adding tooltips tt.create_ToolTip(curRad, 'This is a Radiobutton control') # Add a Progressbar to Tab 2 self.progress_bar = ttk.Progressbar(tab2, orient='horizontal', length=286, mode='determinate') self.progress_bar.grid(column=0, row=3, pady=2) # Create a container to hold buttons buttons_frame = ttk.LabelFrame(self.mighty2, text=' ProgressBar ') buttons_frame.grid(column=0, row=2, sticky='W', columnspan=2) # Add Buttons for Progressbar commands ttk.Button(buttons_frame, text=" Run Progressbar ", command=self.run_progressbar).grid(column=0, row=0, sticky='W') ttk.Button(buttons_frame, text=" Start Progressbar ", command=self.start_progressbar).grid(column=0, row=1, sticky='W') ttk.Button(buttons_frame, text=" Stop immediately ", command=self.stop_progressbar).grid(column=0, row=2, sticky='W') ttk.Button(buttons_frame, text=" Stop after second ", command=self.progressbar_stop_after).grid(column=0, row=3, sticky='W') for child in buttons_frame.winfo_children(): child.grid_configure(padx=2, pady=2) for child in self.mighty2.winfo_children(): child.grid_configure(padx=8, pady=2) # Creating a Menu Bar menu_bar = Menu(self.win) self.win.config(menu=menu_bar) # Add menu items file_menu = Menu(menu_bar, tearoff=0) file_menu.add_command(label="New") file_menu.add_separator() file_menu.add_command(label="Exit", command=self._quit) menu_bar.add_cascade(label="File", menu=file_menu) # Display a Message Box def _msgBox(): msg.showinfo('Python Message Info Box', 'A Python GUI created using tkinter:\nThe year is 2017.') # Add another Menu to the Menu Bar and an item help_menu = Menu(menu_bar, tearoff=0) help_menu.add_command(label="About", command=_msgBox) # display messagebox when clicked menu_bar.add_cascade(label="Help", menu=help_menu) # Change the main windows icon self.win.iconbitmap('pyc.ico') # It is not necessary to create a tk.StringVar() # strData = tk.StringVar() strData = self.spin.get() print("Spinbox value: " + strData) # call function self.usingGlobal() self.name_entered.focus() # Add Tooltips ----------------------------------------------------- # Add a Tooltip to the Spinbox tt.create_ToolTip(self.spin, 'This is a Spinbox control') # Add Tooltips to more widgets tt.create_ToolTip(self.name_entered, 'This is an Entry control') tt.create_ToolTip(self.action, 'This is a Button control') tt.create_ToolTip(self.scrol, 'This is a ScrolledText control')
# Place labels into the container element ttk.Label(buttons_frame, text="Label1").grid(column=0, row=0, sticky=tk.W) ttk.Label(buttons_frame, text="Label2").grid(column=1, row=0, sticky=tk.W) ttk.Label(buttons_frame, text="Label3").grid(column=2, row=0, sticky=tk.W) # Exit GUI cleanly def _quit(): win.quit() win.destroy() exit() # Creating a Menu Bar menu_bar = Menu(win) win.config(menu=menu_bar) # Add menu items file_menu = Menu(menu_bar, tearoff=0) file_menu.add_command(label="New") file_menu.add_separator() file_menu.add_command(label="Exit", command=_quit) menu_bar.add_cascade(label="File", menu=file_menu) # Display a Message Box def _msgBox(): # msg.showinfo('Python Message Info Box', 'A Python GUI created using tkinter:\nThe year is 2017.') # msg.showwarning('Python Message Warning Box', 'A Python GUI created using tkinter:\nWarning: There might be a bug in this code.') # msg.showerror('Python Message Error Box', 'A Python GUI created using tkinter:\nError: Houston ~ we DO have a serious PROBLEM!')
def __init__(self, master): self.master = master self.master.title("Lexicon Creator") self.master.geometry("250x220") self.master.resizable(False, False) foldercreation("Lexicons") self.createlex = "" self.wordlabel = Label( self.master, text="Word", ) self.wordlabel.pack() self.wordT = Text(self.master, height=1, state="disabled") self.wordT.pack() self.deflablel = Label(self.master, text="Definition") self.deflablel.pack() self.defT = Text(self.master, height=4, state="disabled") self.defT.pack() self.cleardb = Button(self.master, text="Clear Definition", state="disabled", command=self.cleardf) self.cleardb.pack() self.clearwb = Button(self.master, text="Clear Word", state="disabled", command=self.clearwf) self.clearwb.pack() self.addb = Button(self.master, text="Add", state="disabled", command=self.addw) self.addb.pack() #menu self.menu = Menu(self.master) self.file_menu = Menu(self.menu, tearoff=0) self.file_menu.add_command(label="Create Lexicon", accelerator='Ctrl+N', command=self.create_l) self.file_menu.add_command(label="Load Lexicon", accelerator='Ctrl+L', command=self.load_l) self.file_menu.add_command(label="Add Word", accelerator='Ctrl+O', command=self.addw) self.file_menu.add_command(label="Close File", accelerator='Ctrl+F4', command=self.cfile, state="disabled") self.file_menu.add_command(label="Exit", accelerator='Alt+F4', command=self.exitmenu) self.menu.add_cascade(label="File", menu=self.file_menu) self.edimenu = Menu(self.menu, tearoff=0) self.edimenu.add_command(label="Reset", accelerator='Ctrl+Z', command=self.reset) self.edimenu.add_command(label="Clear Word", accelerator='Alt+Z', command=self.clearwf) self.edimenu.add_command(label="Clear Definition", accelerator='Alt+D', command=self.cleardf) self.edimenu.add_command(label="Delete Word", accelerator='Ctrl+D', command=self.deleteword) self.menu.add_cascade(label="Edit", menu=self.edimenu) self.showmenu = Menu(self.menu, tearoff=0) self.showmenu.add_command(label="Show Lexicon", accelerator='Ctrl+T', command=self.showlexicon) self.menu.add_cascade(label="Show", menu=self.showmenu) self.about_menu = Menu(self.menu, tearoff=0) self.about_menu.add_command(label="About", accelerator='Ctrl+I', command=aboutmenu) self.menu.add_cascade(label="About", menu=self.about_menu) self.help_menu = Menu(self.menu, tearoff=0) self.help_menu.add_command(label="Help", accelerator='Ctrl+F1', command=helpmenu) self.menu.add_cascade(label="Help", menu=self.help_menu) self.master.config(menu=self.menu) self.master.bind('<Control-z>', lambda event: self.reset()) self.master.bind('<Control-o>', lambda event: self.addw()) self.master.bind('<Alt-d>', lambda event: self.cleardf()) self.master.bind('<Alt-z>', lambda event: self.clearwf()) self.master.bind('<Alt-F4>', lambda event: self.exitmenu()) self.master.bind('<Control-F1>', lambda event: helpmenu()) self.master.bind('<Control-i>', lambda event: aboutmenu()) self.master.bind('<Control-t>', lambda event: self.showlexicon()) self.master.bind('<Control-n>', lambda event: self.create_l()) self.master.bind('<Control-l>', lambda event: self.load_l()) self.master.bind('<Control-F4>', lambda event: self.cfile()) self.master.bind('<Control-d>', lambda event: self.deleteword())
# #contents = self.textPad.get(self, 1.0, END) # The line in question # #textFile.write(contents) # textFile.close() # root.destroy() ################################################################################ # Main Window ################################################################################ window = Tk() window.title("Sketch") window.geometry('1200x800') # wxh ################################################################################ # Menu Bar ################################################################################ menu = Menu(window) item_file = Menu(menu) item_file.add_command(label='New', command=clicked_new) item_file.add_command(label='Open', command=clicked_open) item_file.add_command(label='Save', command=clicked_save) item_file.add_command(label='Save As', command=None) item_file.add_command(label='Close', command=clicked_close) item_file.add_separator() item_file.add_command(label='Other', command=None) item_import = Menu(menu, tearoff=0) item_import.add_command(label='Import sketch', command=None) item_import.add_command(label='import code', command=None) item_run = Menu(menu) item_run.add_command(label='execute', command=None)
frame.config(width=500) frame.config(height=500) def rectangle(): frame.config(width=700) frame.config(height=400) if __name__ == '__main__': root = Tk() frame = Frame(root, width=300, height=100, bg="Black") frame.pack() root_menu = Menu(root) root.config(menu=root_menu) menu1 = Menu(root_menu) root_menu.add_cascade(label="Color", menu=menu1) menu1.add_command(label="Red", command=color_r) menu1.add_command(label="Green", command=color_g) menu1.add_command(label="Blue", command=color_b) menu2 = Menu(root_menu) root_menu.add_cascade(label="Size", menu=menu2) menu2.add_command(label="500x500", command=square) menu2.add_command(label="700x400", command=rectangle) root.mainloop()