def create_path(self): width_msg = 100 width_path = 400 path_frame = Frame(self.root) path_frame.pack(fill=X) # read read_frame = Frame(path_frame) read_frame.pack(fill=X) read_msg = Message(read_frame, width=width_msg, text='Video path:') read_msg.pack(side=LEFT) read_path = Message(read_frame, width=width_path, text='file1') read_path.pack(side=LEFT) read_btn = Button(read_frame, text="Choose file", command=self.click_read) read_btn.pack(side=RIGHT) # save save_frame = Frame(path_frame) save_frame.pack(fill=X) save_msg = Message(save_frame, width=width_msg, text='Save to:') save_msg.pack(side=LEFT) save_path = Message(save_frame, width=width_path, text='file2') save_path.pack(side=LEFT) save_btn = Button(save_frame, text="Choose file", command=self.click_save) save_btn.pack(side=RIGHT) self.read_path = read_path self.save_path = save_path
def callback(event): event.widget.focus_set() print "clicked at", event.x, event.y if self.add_tasks_flg.get() == 1: # Select number of robots # Define elements of pop up window self.top = Toplevel() self.num_robots = StringVar(self.top) self.num_robots.set("1") # default value w = OptionMenu(self.top, self.num_robots, '1', '2', '3', '4').grid(row=0, column=1) text1 = Message(self.top, text="Number of robots:", width=150).grid(row=0, column=0) self.e = Entry(self.top, width=10) self.e.grid(row=1, column=1) text2 = Message(self.top, text="Task duration:", width=150).grid(row=1, column=0) text3 = Message(self.top, text="(s)", width=60).grid(row=1, column=2) newline = Message(self.top, text=" ").grid(row=2) button = Button(self.top, text='Enter', command=lambda: self.enter_task(event)).grid( row=3, column=1) button_cancel = Button(self.top, text='Cancel', command=self.cancel_task).grid(row=3, column=2) center(self.top)
def about(): help_window = tk.Toplevel(master) help_window.geometry("1000x1000") help_window.title("About the Bunimovich Stadia Evolution Viewer") text = Message(help_window, text = TEXT, padx = 100) text.pack()
def create_widgets(self): self.name = StringVar(self.parent) self.fontSize = StringVar(self.parent) self.frameMain = Frame(self, borderwidth=2, relief=SUNKEN) self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH) self.messageInfo = Message(self.frameMain, anchor=W, justify=LEFT, padx=5, pady=5, text=self.message) #,aspect=200) entryName = Entry(self.frameMain, textvariable=self.name, width=30) entryName.focus_set() self.messageInfo.pack(padx=5, pady=5) #, expand=TRUE, fill=BOTH) entryName.pack(padx=5, pady=5) frameButtons = Frame(self, pady=2) frameButtons.pack(side=BOTTOM) self.buttonOk = Button(frameButtons, text='Ok', width=8, command=self.Ok) self.buttonOk.pack(side=LEFT, padx=5) self.buttonCancel = Button(frameButtons, text='Cancel', width=8, command=self.Cancel) self.buttonCancel.pack(side=RIGHT, padx=5)
def __init__(self, wdw, sols): """ Stores the list of solutions in sols and defines the layout of the GUI. """ wdw.title('solutions scroller') self.sols = sols self.cursor = 0 self.lbl = Label(wdw, text="solution : ") self.lbl.grid(row=0, column=0, sticky=E) self.ent = Entry(wdw) self.ent.grid(row=0, column=1, stick=W) self.ent.insert(INSERT, "0 of %d" % len(sols)) self.myft = Font(family="Courier New", size=12, weight="normal") self.mlen = self.myft.measure("M") lines = sols[0].split('\n') self.width = max([len(line) for line in lines]) self.display = StringVar() self.display.set(self.sols[0]) self.mess = Message(wdw, textvariable=self.display, \ font=self.myft, width=self.width*self.mlen, background='white') self.mess.grid(row=1, column=0, columnspan=2) self.btnext = Button(wdw, command=self.next, text='next') self.btnext.grid(row=2, column=1, sticky=W + E) self.btprev = Button(wdw, command=self.previous, text='previous') self.btprev.grid(row=2, column=0, sticky=W + E)
def __init__(self, frame, **kwargs): text = get_dict_item(kwargs, 'text', 'None') font = get_dict_item(kwargs, 'font', 'Arial') width = get_dict_item(kwargs, 'width', '+10') height = get_dict_item(kwargs, 'height', '+5') self.fg = get_dict_item(kwargs, 'fg', 'black') self.fg_hov = get_dict_item(kwargs, 'fg_hov', '') self.bg = get_dict_item(kwargs, 'bg', '') self.bg_hov = get_dict_item(kwargs, 'bg_hov', '') self.function = get_dict_item(kwargs, 'func', 'False') self.function_exc = get_dict_item(kwargs, 'command', 'False') self.img = get_dict_item(kwargs, 'img', '') self.img_hov = get_dict_item(kwargs, 'img_hov', '') if self.img == '': self.msg = Message(frame, text=text) self.msg.config(bg=self.bg, fg=self.fg, width=width, font=font) else: self.msg = Label(frame, image=self.img, width=width, background=self.bg) self.msg.bind("<Enter>", self._enter) self.msg.bind("<Leave>", self._leave) self.msg.bind("<Button-1>", self._click)
def main(): root = Tk() if (len(sys.argv) > 1): mol_filename = sys.argv[1] else: #print >> sys.stderr, "Syntax: %s <mol file> [<svg file>]" % sys.argv[0] mol_filename = askopenfilename(parent=root, title="Pick a MOL file to plot", filetypes=[("MOL files", "*.mol"), ("All Files", "*")]) if (mol_filename == ''): sys.exit(-1) if (len(sys.argv) > 2): svg_filename = sys.argv[2] else: svg_filename = None if (not os.path.isfile(mol_filename)): print >> sys.stderr, "File not found: " + mol_filename sys.exit(-2) #file = open(mol_filename) try: G = molfile2graph(mol_filename) except Exception, strerror: root.title("ERROR") Message(root, text=strerror, width=100).pack() Button(root, text="OK", command=root.destroy).pack() root.mainloop() sys.exit(-1)
def __init__(self, wdgt, delay=1, follow=True): """ Initialize the ToolTip Arguments: wdgt: The widget this ToolTip is assigned to msg: A static string message assigned to the ToolTip msgFunc: A function that retrieves a string to use as the ToolTip text delay: The delay in seconds before the ToolTip appears(may be float) follow: If True, the ToolTip follows motion, otherwise hides """ self.wdgt = wdgt # The parent of the ToolTip is the parent of the ToolTips widget self.parent = self.wdgt.master # Initalise the Toplevel Toplevel.__init__(self, self.parent, bg='black', padx=1, pady=1) # Hide initially self.withdraw() # The ToolTip Toplevel should have no frame or title bar self.overrideredirect(True) # The msgVar will contain the text displayed by the ToolTip self.msgVar = StringVar() self.delay = delay self.follow = follow self.visible = 0 self.lastMotion = 0 Message(self, textvariable=self.msgVar, bg='#FFFFDD', aspect=1000).grid() # The test of the ToolTip is displayed in a Message widget
def __init__(self, master, variable, anchor=W, bordercolor=None, borderwidth=1, padx=0, pady=0, background=None, foreground=None, font=None): Cell.__init__(self, master, background=background, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=borderwidth, bd=0) self._message_widget = Message(self, textvariable=variable, font=font, background=background, foreground=foreground) self._message_widget.pack(expand=True, padx=padx, pady=pady, anchor=anchor)
def encrypt_input(): ourMessage = '' for i in range(len(encryptedinput)): ourMessage += encryptedinput[i] messageVar = Message(inputwindow, text=ourMessage) messageVar.config(bg='lightgray') messageVar.config(aspect=400) messageVar.grid()
def Msg(name): master = tk() master.title('Error message') msg = Message(master, text='unable to load ' + name + ' from file') # msg.config() msg.pack() # close_button = Button(master, text='OK', command=master.destroy) mainloop()
def path(self): path_frame=LabelFrame(self.window,text='Input paths',width=450,height=100) path_frame.place(x=20,y=60) ora_mes=Message(path_frame,text='Excel from ORA:',width=120) ora_mes.place(x=10,y=0) self.ora_entry=Entry(path_frame,textvariable=self.ora_path,width=35) self.ora_entry.place(x=130,y=0) ora_button=Button(path_frame,text='Select…',command=self.selectPath1) ora_button.place(x=365,y=0) calcu_mes=Message(path_frame,text='Calculator:',width=120) calcu_mes.place(x=10,y=40) self.calcu_entry=Entry(path_frame,textvariable=self.calcu_path,width=35) self.calcu_entry.place(x=130,y=40) calcu_button=Button(path_frame,text='Select…',command=self.selectPath2) calcu_button.place(x=365,y=40)
def About(): top = Toplevel() top.title("About this application...") msg = Message(top, text="Turing Machine simulator\nWritten on python 2.7 \ using Tkinter\n2016 Kyiv, IASA\nby Illya Barziy") msg.pack() button = Button(top, text="OK", command=top.destroy) button.pack()
def message_box_notification(self, txt): #crate the top level for message box mess_box = Toplevel() mess_box.title("Message") #create the message text msg = Message(mess_box, text = txt) msg.pack() #create top level close button mess_box_close = Button(mess_box, text = "OK", command = mess_box.destroy) mess_box_close.pack()
def render_header(self, title, buttons): Label(self.tk, text=title, font=("Helvetica", 20)).pack() Message(self.tk, textvariable=self.info_label_text, fg="red", justify=LEFT, width=500).pack() self.render_window_frames() for i in xrange(len(buttons)): Button(self.header_frame, text=buttons[i]['title'], command=buttons[i]['callback']).pack(side=LEFT)
def create_widgets(self): """Creates buttons on the window and binds actions to them""" #listbox for the equations self.fields = Listbox(self, selectmode=SINGLE) self.fields.config(width=100) self.fields.pack() #button for calculating self.calculate_button = Button(self) self.calculate_button["text"] = "Calculate" self.calculate_button["command"] = self.calculate self.calculate_button.pack({"side": "left"}) #to the end self.show_result_floating = Message(self, width=250) self.show_result_floating.pack() #second Message self.show_result_interval = Message(self, width=250) self.show_result_interval.pack() #adding menu buttons to the window self.menubar = Menu(self) self.menubar.add_command(label="Load file", command=self.read_json_file) self.menubar.add_command(label="Quit", command=self.quit)
def help_f(self): top = Toplevel() top.title("HELP") msg = Message(top, width=500, text="Noise Threshold (NT) - Noise Based Main Threshold \ (Sigmas)\n Threshold 1 - Main Threshold (LSBs) \n Threshold 2 - End of Pulse Error \n \ Threshold 3 - End of Tail Error \n When Thr1 = Thr3 = 0 their values are defined as: \n \ (THR1 = NT (LSBs) / THR3 = NT*NOISE_ADC / 5)") msg.pack() button = Button(top, text="Close", command=top.destroy) button.pack()
def __init__(self): self.master = Tk() self.master.title('About fabian') frame = Frame(self.master, width=500, height=400, bd=1) frame.pack() frameAbout = Frame(frame, bd=0) message = \ """ Key short cuts Main window: o - open new file q - quit application C - Close all opened windows z - zoom in x - zoom out right arrow - next image left arrow - previous image a - see "help - about" h - see "help - help" Change tools: F1 - activate zoom tool F2 - activate line profile tool F3 - activate intensity projections on vertical/horizontal box sides F4 - activate relief plot tool F5 - activate rocking curve tool Control peaks: p - show/hide peaks found by ImageD11 peaksearch c - clear peaks from memory r - read a peaks file (spt) Auto update images: f - activate/deactivate "File - auto file update" up-arrow - add 0.5 sec. to time delay between loading files in auto file update mode down-arrow - subtract 0.5 sec. from the time delay between loading files in auto file update mode 2D plot window: a - auto scale plot p - print/save plot q - quit 2D plot """ Message(frameAbout, text=message, width=500).pack(fill=X, padx=5) frameAbout.pack(expand=1, pady=10, padx=5) frameAbout = Frame(frame, bd=0) Button(frameAbout,text='So what', bg='red', command=self.quit)\ .pack(side=RIGHT) frameAbout.pack(expand=1, pady=10, padx=5)
def vis_thread(): global txt, color, txt2, color2 def update(): global txt, color, txt2, color2 msg.config(text=txt, background=color) msg2.config(text=txt2, background=color2) root.after(250, update) root = Tk() root.geometry("900x600") msg = Message(root, text=txt, background=color) msg.config(font=('times', 200, 'italic bold')) msg.pack() msg2 = Message(root, text=txt2, background=color2) msg2.config(font=('times', 70, 'italic bold')) msg2.pack() root.after(250, update) root.mainloop()
def help_f(self): top = Toplevel() top.title("HELP") msg = Message(top, width=500, text="COEFF Calibration Procedure: \n \ Input Start Point and Length of the pulse \n \ Input an initial guess of the pulse amplitude \n \ Use a ROI with at least 1000 samples of baseline \n \ and 1000 samples after pulse end \n \ Adjust loop range and step until a graph error \n \ with a minimum is observed \n \ Refine the search to increase precision") msg.pack() button = Button(top, text="Close", command=top.destroy) button.pack()
def __init__(self, master, variable, anchor=CENTER, bordercolor=None, borderwidth=1, padx=0, pady=0, background=None, foreground=None, font=None): """ Parameters ---------- :param master: the master of the data cell :param variable: data variable :param anchor: anchor :param bordercolor: the color of the border :param borderwidth: the width of the data cell border :param padx: x coordinate padding :param pady: y coordinate padding :param background: background color :param foreground: foreground color :param font: text font """ Cell.__init__(self, master, background=background, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=borderwidth, bd=0) self._message_widget = Message(self, textvariable=variable, font=font, background=background, foreground=foreground) self._message_widget.pack(padx=padx, pady=pady, anchor=anchor) self._message_widget.configure(width=110, pady=1.2)
def __init__(self): self.master = Tk() self.master.title('About fabian') frame = Frame(self.master, width=500, height=400, bd=1) frame.pack() frameAbout = Frame(frame, bd=0) message = "\nfabian (%s) was brought to you by \n\n\ Henning O. Sorensen & Erik Knudsen\n\ Center for Fundamental Research: Metal Structures in Four Dimensions\n\ Risoe National Laboratory\n\ Frederiksborgvej 399\n\ DK-4000 Roskilde\n\ email: [email protected]"%(Fabian.__version__) Message(frameAbout, text=message,width=500).pack(fill=X, padx=5) frameAbout.pack(expand=1, pady=10, padx=5) frameAbout = Frame(frame, bd=0) Button(frameAbout,text='So what', bg='red', command=self.quit)\ .pack(side=RIGHT) frameAbout.pack(expand=1, pady=10, padx=5)
def inputinfo(self): tabControl=ttk.Notebook(self.window) match=ttk.Frame(tabControl,width=450,height=328) tabControl.add(match,text=' -Match- ') battle=ttk.Frame(tabControl,width=450,height=328) tabControl.add(battle,text=' -Fight- ') scene=ttk.Frame(tabControl,width=450,height=328) tabControl.add(scene,text=' -Round- ') tabControl.place(x=20,y=180) #Match Info num=Message(match,text='Game No.',width=70) num.place(x=10,y=10) self.num_entry=Entry(match,width=6,textvariable=self.MATCH.gameNum) self.num_entry.place(x=80,y=10) mapName=Message(match,text='Map:',width=50) mapName.place(x=130,y=10) self.mapName_cb=ttk.Combobox(match,width=10,textvariable=self.MATCH.mapNum) self.mapName_cb['values']=mapList self.mapName_cb.place(x=180,y=10) time=Message(match,text='Duration:',width=100) time.place(x=280,y=10) self.time_entry=Entry(match,width=10,textvariable=self.MATCH.gameTime) self.time_entry.place(x=350,y=10) def selectTeamA(*args): team_selected=teamA_cb.current() y=20 for i in range(0,6): self.ap.insert(i,ttk.Combobox(teamA_frame,width=10)) print self.ap[i] self.ap[i]['values']=allPlayers.get(teamList[team_selected],' ') name='Player'+str(i+1) self.ap[i].insert(0,name) self.ap[i].place(x=10,y=y+20*(i+1)) for i in range(0,6): self.ah.insert(i,ttk.Combobox(teamA_frame,width=10)) self.ah[i]['values']=heroList name='hero' self.ah[i].insert(0,name) self.ah[i].place(x=105,y=y+20*(i+1)) def selectTeamB(*args): team_selected=teamB_cb.current() y=20 for i in range(0,6): self.bp.insert(i,ttk.Combobox(teamB_frame,width=10)) self.bp[i]['values']=allPlayers.get(teamList[team_selected],' ') name='Player'+str(i+7) self.bp[i].insert(0,name) self.bp[i].place(x=10,y=y+20*(i+1)) for i in range(0,6): self.bh.insert(i,ttk.Combobox(teamB_frame,width=10)) self.bh[i]['values']=heroList name='hero' self.bh[i].insert(0,name) self.bh[i].place(x=105,y=y+20*(i+1)) #Team A information teamA_frame=LabelFrame(match,text='TeamA',width=210,height=200) teamA_frame.place(x=10,y=50) teamA_name=Message(teamA_frame,text='Name:',width=70) teamA_name.place(x=10,y=10) teamA_cb=ttk.Combobox(teamA_frame,width=12,textvariable=self.MATCH.teamA) teamA_cb['values']=teamList teamA_cb.bind('<<ComboboxSelected>>',selectTeamA) teamA_cb.place(x=60,y=10) #Team B information teamB_frame=LabelFrame(match,text='TeamB',width=210,height=200) teamB_frame.place(x=230,y=50) teamB_name=Message(teamB_frame,text='Name:',width=70) teamB_name.place(x=10,y=10) teamB_cb=ttk.Combobox(teamB_frame,width=12,textvariable=self.MATCH.teamB) teamB_cb['values']=teamList teamB_cb.bind('<<ComboboxSelected>>',selectTeamB) teamB_cb.place(x=60,y=10) self.A=teamA_cb self.B=teamB_cb winner=Message(match,text='Match Winner:',width=150) winner.place(x=10,y=260) self.winteam=IntVar() if self.MATCH.finalwinner == 'A': self.winteam.set(1) if self.MATCH.finalwinner == 'B': self.winteam.set(2) winA=Radiobutton(match,text='TeamA',variable=self.winteam,value=1) winB=Radiobutton(match,text='TeamB',variable=self.winteam,value=2) winA.place(x=110,y=260) winB.place(x=180,y=260) attacker=Message(match,text='First Attack:',width=150) attacker.place(x=10,y=280) self.attackteam=IntVar() if self.MATCH.attack == 'A': self.attackteam.set(1) if self.MATCH.attack == 'B': self.attackteam.set(2) attackA=Radiobutton(match,text='TeamA',variable=self.attackteam,value=1) attackB=Radiobutton(match,text='TeamB',variable=self.attackteam,value=2) attackA.place(x=110,y=280) attackB.place(x=180,y=280) matchSave=Button(match,text='Save',width=10,command=self.savematch) matchSave.place(x=330,y=290) #Battle Info battle_label=Label(battle,textvariable=self.BATTLE.caption,width=15,height=1) battle_label.place(x=0,y=20) start_tag=Label(battle,text='Start time:',foreground='black',width=8,height=1) start_tag.place(x=100,y=10) self.start_entry=Entry(battle,width=20,textvariable=self.BATTLE.start_time,foreground='black') self.start_entry.place(x=200,y=10) end_tag=Label(battle,text='End time:',foreground='black',width=8,height=1) end_tag.place(x=100,y=40) self.end_entry=Entry(battle,width=20,textvariable=self.BATTLE.end_time,foreground='black') self.end_entry.place(x=200,y=40) #winner win_tag=Label(battle,text='Fight Winner:',foreground='black',width=10,height=1) #标签 win_tag.place(x=100,y=70) self.team=IntVar() self.team.set(1) team1=Radiobutton(battle,text='Team A',variable=self.team,value=1) team1.place(x=200,y=70) team2=Radiobutton(battle,text='Team B',variable=self.team,value=2) team2.place(x=270,y=70) next_button=Button(battle,text='Next',width=10,command=self.battlenext) next_button.place(x=100,y=100) alter_tag=Label(battle,text='Input fight number to alter information:') #标签 alter_tag.place(x=30,y=150) self.alter_entry=Entry(battle,width=5) self.alter_entry.place(x=280,y=150) alter_button=Button(battle,text='Go',width=7,command=self.fightalter) alter_button.place(x=330,y=150) battleSave=Button(battle,text='Save',width=10,command=self.savefight) battleSave.place(x=330,y=290) #Round Info round_label=Label(scene,textvariable=self.ROUND.caption,width=15,height=1) round_label.place(x=0,y=20) sstart_tag=Label(scene,text='Start time:',foreground='black',width=8,height=1) sstart_tag.place(x=100,y=10) self.sstart_entry=Entry(scene,width=20,textvariable=self.ROUND.start_time,foreground='black') self.sstart_entry.place(x=200,y=10) send_tag=Label(scene,text='End time:',foreground='black',width=8,height=1) send_tag.place(x=100,y=40) self.send_entry=Entry(scene,width=20,textvariable=self.ROUND.end_time,foreground='black') self.send_entry.place(x=200,y=40) snext_button=Button(scene,text='Next',width=10,command=self.roundnext) snext_button.place(x=100,y=100) salter_tag=Label(scene,text='Input battle number to alter information:') #标签 salter_tag.place(x=30,y=150) self.salter_entry=Entry(scene,width=5) self.salter_entry.place(x=280,y=150) salter_button=Button(scene,text='Go',width=7,command=self.roundalter) salter_button.place(x=330,y=150) sceneSave=Button(scene,text='Save',width=10,command=self.saveround) sceneSave.place(x=330,y=290)
width3 = 50 width3 = 300 score = 0 tk = Tk() tk.title("Game") tk.resizable(0, 0) # not resizable tk.wm_attributes("-topmost", 1) # at top btn1 = Button(tk, text='简单', command=test1) btn2 = Button(tk, text='难', command=test2) bth3 = Button(tk, text='超级', command=test3) btn1.pack(side='left') btn2.pack(side='left') canvas = Canvas(tk, width=500, height=350, bd=0, highlightthickness=0) canvas.pack() canvas.create_line(10, 10, 10, 600, fill='red') tk.update() paddle = Paddle(canvas, 'blue', width3) ball = Ball(canvas, paddle, 'green') while True: if ball.hit_bottom == False: ball.draw() paddle.draw() else: Message(title='失败!', Message="你的分数为:" + str(score)) time.sleep(2) break tk.update_idletasks() tk.update() time.sleep(0.01)
print "Script running at: " + runningPath #Build Root UI Window root1 = tk.Tk() root1.iconbitmap( 'C:\Users\Landon\Desktop\Python Workspace\Steam-Library-Exporter\steambmp.ico' ) root1.wm_title('Steam Library Exporter v0.9') root1.tk_setPalette(background="#FFFFFF", foreground="black") #Build Text & Entry Window Elements packable_update = Label(root1, text='Ready!') welcomeMessage = "Welcome to Steam Library Exporter!" secondMessage = "This app gathers your entire Steam library from the web and all available stats within. \nIt even generates a handy Excel/Numbers spreadsheet for you!" welcome1 = Message(root1, text=welcomeMessage, width=500, justify='center') welcome2 = Message(root1, text=secondMessage, width=500, justify='center') label = tk.Label(root1, text='Enter your Steam Login ID: ') entry = tk.Entry(root1) entry.focus_set() #Image UI steamLogo = ImageTk.PhotoImage( Image.open( 'C:\Users\Landon\Desktop\Python Workspace\Steam-Library-Exporter\steamExporterBanner.png' )) panel = tk.Label(root1, image=steamLogo) "------------------------------------- MAIN METHOD -------------------------------------"
to=200, orient=HORIZONTAL, length=170, width=10, variable=LepTmassMax_val, bg="lavender", label="Maximum transverse mass") emptyf2 = Frame(OptionsLep, width="170") #just to mantain OptionsLep width #Question mark to be next to "invariant mass" option qinvmass = Canvas(OptionsLep, width=16, height=16) qinvmass.create_image(8, 8, image=questionmark) infoinvmass = Message(OptionsLep, text="The invariant mass of the charged leptons", bg="White", aspect=300) #Information message def on_enterinvmass(event): """shows an explanation if cursor placed over question mark""" infoinvmass.grid(row=0, rowspan=8) def on_leaveinvmass(event): """hides explanation if cursor not placed on question mark""" infoinvmass.grid_forget() #Def and bind two functions for when cursor is over question mark or leaves qinvmass.bind("<Enter>", on_enterinvmass)
def cateUI(self): self.frame0.destroy() self.initUIRoot() frame4 = Frame(self.frame0, relief=RAISED, borderwidth=1) frame4.pack(fill=BOTH) frame1 = Frame(self.frame0, relief=RAISED, borderwidth=1) frame1.pack(fill=BOTH, expand=True) frame1.columnconfigure(0, weight=1) # frame1.columnconfigure(9, weight=1) frame1.rowconfigure(0, weight=1) lbl = Label(frame4, text="已输入温度组数") lbl.grid(row=0, column=0, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) self.varCountT = StringVar() self.countT = Message(frame4, textvariable=self.varCountT) self.varCountT.set('0') self.countT.grid(row=0, column=2, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) factor_Tree = ttk.Treeview(frame1) factor_Tree['show'] = 'headings' factor_Tree["columns"] = ['t_resid', 't', 'r_oil', 'p', 'Y0', 'Y_results', 'w_aro', 'w_nitro'] # factor_Tree.heading("t", text="温度") factor_Tree.column("t", width=self.winfo_width() / 8) factor_Tree.heading("r_oil", text="剂油比") factor_Tree.column("r_oil", width=self.winfo_width() / 8) factor_Tree.heading("p", text="压力") factor_Tree.column("p", width=self.winfo_width() / 8) factor_Tree.heading("Y0", text="初始组成") factor_Tree.column("Y0", width=self.winfo_width() / 8) factor_Tree.heading("Y_results", text="产物组成") factor_Tree.column("Y_results", width=self.winfo_width() / 8) factor_Tree.heading("w_aro", text="重芳烃含量") factor_Tree.column("w_aro", width=self.winfo_width() / 8) factor_Tree.heading("w_nitro", text="碱氮含量") factor_Tree.column("w_nitro", width=self.winfo_width() / 8) factor_Tree.heading("t_resid", text="停留时间") factor_Tree.column("t_resid", width=self.winfo_width() / 8) factor_Tree.grid(row=0, column=0, pady=4, padx=5) self.factor_Tree = factor_Tree frame2 = Frame(self.frame0, relief=RAISED, borderwidth=1) frame2.pack(fill=BOTH, expand=True) frame2.columnconfigure(0, weight=1) frame2.columnconfigure(8, weight=1) lbl = Label(frame2, text="停留时间(s)") lbl.grid(row=0, column=0, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) self.t_input = Entry(frame2) self.t_input.grid(row=0, column=2, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) lbl = Label(frame2, text="温度(K)") lbl.grid(row=1, column=0, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) self.T_input = Entry(frame2) self.T_input.grid(row=1, column=2, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) lbl = Label(frame2, text="剂油比") lbl.grid(row=2, column=0, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) self.roil_input = Entry(frame2) self.roil_input.grid(row=2, column=2, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) lbl = Label(frame2, text="压力(KPa)") lbl.grid(row=3, column=0, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) self.p_input = Entry(frame2) self.p_input.grid(row=3, column=2, columnspan=2, rowspan=1, sticky=E, pady=4, padx=5) lbl = Label(frame2, text="初始组成(<1 英文逗号分割):") lbl.grid(row=0, column=4, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) self.Y0_input = Entry(frame2) self.Y0_input.grid(row=0, column=6, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) lbl = Label(frame2, text="产物组成(<1 英文逗号分割):") lbl.grid(row=1, column=4, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) self.Y_results_input = Entry(frame2) self.Y_results_input.grid(row=1, column=6, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) lbl = Label(frame2, text="碱氮含量(<1)") lbl.grid(row=2, column=4, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) self.yn_input = Entry(frame2) self.yn_input.insert(0, 0.0) self.yn_input.grid(row=2, column=6, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) lbl = Label(frame2, text="重芳烃含量(<1)") lbl.grid(row=3, column=4, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) self.ya_input = Entry(frame2) self.ya_input.grid(row=3, column=6, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) lbl = Label(frame2, text="分子质量(逗号分割)") lbl.grid(row=4, column=4, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) self.Molmasses_input = Entry(frame2) self.Molmasses_input.grid(row=4, column=6, columnspan=2, rowspan=1, sticky=W, pady=4, padx=5) self.Molmasses_input.insert('0.8,1.1,1.8,0.2,0.2,0.2,0.11,0.016,0.042,0.056,0.05,0.012') addButton = Button(frame2, command=self.addFactors, text="添加条件") addButton.grid(row=9, column=2, sticky=E) self.newCatButton = Button(frame2, command=self.newCata, text="开始计算", state=DISABLED) self.newCatButton.grid(row=9, column=6, sticky=E)
def __init__(self, master=None): """ Constructor """ Frame.__init__(self, master, name='pvApplication', bg='black', padx=5, pady=5) # set black background, pad sides with 15 points, top/bottom 5 points # fill=BOTH fills in padding with background color # w/o fill=BOTH padding is default color # side=TOP is the default self.pack(fill=BOTH) master.resizable(False, False) # not resizable in x or y master.title(PVAPP_TXT) # set title bar of master (a.k.a. root) master.protocol("WM_DELETE_WINDOW", self._quit) # close window to quit self.validationConstants = self.readJSON('validationConstants') self.messagetext = self.readJSON('messagetext' + '.' + LANGUAGE) MAX_STRINGS = self.validationConstants["pvapplication"]["numStrs"] MAX_MODULES = self.validationConstants["pvapplication"]["numMods"] MAX_SUNS = self.validationConstants["pvapplication"]["sysEe"] CAPTION_FONT = nametofont('TkCaptionFont') # font for titles # PVsystem pvSys = self.pvSys = PVsystem() # variables numStrs = self.numStrs = IntVar(self, NUMBERSTRS, 'numStrs') numMods = self.numMods = IntVar(self, NUMBERMODS, 'numMods') numCells = self.numCells = IntVar(self, NUMBERCELLS, 'numCells') txtIsys = self.txtIsys = DoubleVar(self, name='txtIsys') txtVsys = self.txtVsys = DoubleVar(self, name='txtVsys') txtPsys = self.txtPsys = DoubleVar(self, name='txtPsys') txtImp = self.txtImp = StringVar(self, name='txtImp') txtVmp = self.txtVmp = StringVar(self, name='txtVmp') txtPmp = self.txtPmp = StringVar(self, name='txtPmp') txtIsc = self.txtIsc = StringVar(self, name='txtIsc') txtVoc = self.txtVoc = StringVar(self, name='txtVoc') txtFF = self.txtFF = StringVar(self, name='txtFF') txtEff = self.txtEff = StringVar(self, name='txtEff') sysEe = self.sysEe = DoubleVar(self, 1, name='sysEe') txtImp.set("{:7.3f}".format(self.pvSys.Imp)) # [A] txtVmp.set("{:7.3f}".format(self.pvSys.Vmp)) # [V] txtPmp.set("{:7.3f}".format(self.pvSys.Pmp / 1000)) # [kW] txtIsc.set("{:7.3f}".format(self.pvSys.Isc)) # [A] txtVoc.set("{:7.3f}".format(self.pvSys.Voc)) # [V] txtFF.set("{:7.3f}".format(self.pvSys.FF * 100)) # [%] txtEff.set("{:7.3f}".format(self.pvSys.eff * 100)) # [%] self.msgtext = StringVar(self, READY_MSG, 'msgtext') # must register vcmd and invcmd as Tcl functions vcmd = (self.register(self.validateWidget), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') invcmd = (self.register(self.invalidWidget), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') # SP logo # convert image to tk-compatible format (.gif, .pgm, or .ppm) self.SPlogo = ImageTk.PhotoImage(Image.open(SPLOGO)) # bg='black' fills extra space with black # anchor=W aligns photoimage on left side, NW is no different # padding is ignored by images, use borderwidth Label(self, image=self.SPlogo, borderwidth=5, bg='black', anchor=W).pack(fill=BOTH) # fill=BOTH expands the photoimage to fill parent frame # w/o fill=BOTH photoimage is centered in frame even with anchor=W # Intro text introText = 'PVmismatch calculates I-V and P-V curves as well as the' introText += ' max power point (MPP) for any sized system.\nSet the' introText += ' number of strings in the system, the number of modules' introText += ' per string and the number cells per module.' # anchor=W aligns message on left side, NW is no different # fg='white' sets text color to white, default is black, so it doesn't # show on black background # default aspect is 150%, about as wide as high, or set width>0 Message(self, text=introText, width=750, bg='black', fg='white', anchor=W).pack(fill=BOTH) # fill=BOTH expands the message to fill parent frame # w/o fill=BOTH message is centered in frame even with anchor=W # PVsystem frame pvSysFrame = self.pvSysFrame = Frame(master, name='pvSysFrame') # fill=BOTH keeps widgets in frame on left when window is resized pvSysFrame.pack(fill=BOTH) # PVsystem matplotlib figure canvas self.pvSysPlotFrame = Frame(pvSysFrame, name='pvSysPlotFrame') pvSysPlotFrame = self.pvSysPlotFrame pvSysPlotFrame.pack(side=RIGHT) pvSysPlot = self.pvSysPlot = pvSys.plotSys() self.pvSysFigCanvas = FigureCanvasTkAgg(pvSysPlot, master=pvSysPlotFrame, resize_callback=None) pvSysFigCanvas = self.pvSysFigCanvas pvSysFigCanvas.get_tk_widget()._name = 'pvSysFigCanvas' # IGNORE:W0212 pvSysFigCanvas.show() # NB: FigureCanvasTkAgg._tkcanvas is FigureCanvasTkAgg.get_tk_widget() pvSysFigCanvas.get_tk_widget().pack(fill=BOTH) pvSysToolbar = NavigationToolbar2TkAgg(pvSysFigCanvas, pvSysPlotFrame) pvSysToolbar.update() pvSysToolbar.pack(fill=BOTH) # PVsystem data frame pvSysDataFrame = self.pvSysDataFrame = Frame(pvSysFrame, name='pvSysDataFrame') pvSysDataFrame.pack(side=LEFT) _row = 0 Label(pvSysDataFrame, text='PVsystem', font=CAPTION_FONT).grid(row=_row, columnspan=3, sticky=W) # number of strings _row += 1 # row 1 Label(pvSysDataFrame, text='Number of Strings').grid(row=_row, columnspan=2, sticky=W) # use textVar to set number of strings from LOAD, RESET or default spinboxCnf = { 'name': 'numStrSpinbox', 'from_': 1, 'to': MAX_STRINGS, 'textvariable': numStrs, 'width': 5, 'validate': 'all', 'validatecommand': vcmd, 'invalidcommand': invcmd, 'command': self.updatePVsys } self.numStrSpinbox = Spinbox(pvSysDataFrame, cnf=spinboxCnf) self.numStrSpinbox.bind("<Return>", self.keyBinding) self.numStrSpinbox.grid(row=_row, column=2) # number of modules _row += 1 # row 2 Label(pvSysDataFrame, text='Number of Modules').grid(row=_row, columnspan=2, sticky=W) # number of modules spinbox spinboxCnf = { 'name': 'numModSpinbox', 'from_': 1, 'to': MAX_MODULES, 'textvariable': numMods, 'width': 5, 'validate': 'all', 'validatecommand': vcmd, 'invalidcommand': invcmd, 'command': self.updatePVsys } self.numModSpinbox = Spinbox(pvSysDataFrame, cnf=spinboxCnf) self.numModSpinbox.bind("<Return>", self.keyBinding) self.numModSpinbox.grid(row=_row, column=2) # number of cells _row += 1 # row 3 Label(pvSysDataFrame, text='Number of Cells').grid(row=_row, columnspan=2, sticky=W) # http://www.logilab.org/card/pylintfeatures#basic-checker # pylint: disable = W0142 self.numCellOption = OptionMenu(pvSysDataFrame, numCells, *MODSIZES, command=self.updatePVsys) # pylint: enable = W0142 self.numCellOption._name = 'numCellOption' # IGNORE:W0212 self.numCellOption.grid(row=_row, column=2) # Advanced Configuration button _row += 1 # row 14 buttonCnf = { 'name': 'advCnfButton', 'text': 'Advanced Configuration', 'command': self.startAdvCnf_tk } pvStrButton = self.pvStrButton = Button(pvSysDataFrame, buttonCnf) pvStrButton.grid(row=_row, columnspan=3, sticky=(E + W)) # slider to explore IV curves _row += 1 # row 4, 5 & 6 self.pvSysScale = Scale(pvSysDataFrame, orient=HORIZONTAL, label='I-V Curve', font=CAPTION_FONT, command=self.getIV, showvalue=False, from_=0, to=(pvSys.pvconst.npts - 1)) self.pvSysScale.grid(row=_row, columnspan=3, sticky=(E + W)) # Isys Label(pvSysDataFrame, text='Isys [A]').grid(row=(_row + 1)) self.pvIsys = Entry(pvSysDataFrame, textvariable=txtIsys, width=7) self.pvIsys.grid(row=(_row + 2)) # Vsys Label(pvSysDataFrame, text='Vsys [V]').grid(row=(_row + 1), column=1) self.pvVsys = Entry(pvSysDataFrame, textvariable=txtVsys, width=7) self.pvVsys.grid(row=(_row + 2), column=1) # Psys Label(pvSysDataFrame, text='Psys [kW]').grid(row=(_row + 1), column=2) self.pvPsys = Entry(pvSysDataFrame, textvariable=txtPsys, width=7) self.pvPsys.grid(row=(_row + 2), column=2) # Imp, Vmp & Pmp _row += 3 # row 7, 8, 9, 10, 11 & 12 Label(pvSysDataFrame, text='I-V Characteristics', font=CAPTION_FONT).grid(row=_row, columnspan=3, sticky=W) Label(pvSysDataFrame, text='Imp [A]').grid(row=(_row + 1)) Label(pvSysDataFrame, text='Vmp [V]').grid(row=(_row + 1), column=1) Label(pvSysDataFrame, text='Pmp [kW]').grid(row=(_row + 1), column=2) self.pvImp = Entry(pvSysDataFrame, textvariable=txtImp, width=7, state='readonly') self.pvImp.grid(row=(_row + 2)) self.pvVmp = Entry(pvSysDataFrame, textvariable=txtVmp, width=7, state='readonly') self.pvVmp.grid(row=(_row + 2), column=1) self.pvPmp = Entry(pvSysDataFrame, textvariable=txtPmp, width=7, state='readonly') self.pvPmp.grid(row=(_row + 2), column=2) # Isc, Voc & FF Label(pvSysDataFrame, text='Isc [A]').grid(row=(_row + 3)) Label(pvSysDataFrame, text='Voc [V]').grid(row=(_row + 3), column=1) Label(pvSysDataFrame, text='FF [%]').grid(row=(_row + 3), column=2) self.pvIsc = Entry(pvSysDataFrame, textvariable=txtIsc, width=7, state='readonly') self.pvIsc.grid(row=(_row + 4)) self.pvVoc = Entry(pvSysDataFrame, textvariable=txtVoc, width=7, state='readonly') self.pvVoc.grid(row=(_row + 4), column=1) self.pvFF = Entry(pvSysDataFrame, textvariable=txtFF, width=7, state='readonly') self.pvFF.grid(row=(_row + 4), column=2) Label(pvSysDataFrame, text='Efficiency [%]').grid(row=(_row + 5), columnspan=2) self.pvEff = Entry(pvSysDataFrame, textvariable=txtEff, width=7, state='readonly') self.pvEff.grid(row=(_row + 5), column=2) # set suns _row += 6 # row 13 Label(pvSysDataFrame, text='Irradiance [suns]', font=CAPTION_FONT).grid(row=_row, columnspan=2, sticky=W) # number of modules spinbox spinboxCnf = { 'name': 'sunSpinbox', 'from_': 0.2, 'to': MAX_SUNS, 'increment': 0.1, 'textvariable': sysEe, 'width': 5, 'validate': 'all', 'validatecommand': vcmd, 'invalidcommand': invcmd, 'command': self.updatePVsys } self.sunSpinbox = Spinbox(pvSysDataFrame, cnf=spinboxCnf) self.sunSpinbox.bind("<Return>", self.keyBinding) self.sunSpinbox.grid(row=_row, column=2) # PVstring button _row += 1 # row 14 buttonCnf = { 'name': 'pvStrButton', 'text': 'PVstring', 'command': self.startPVstring_tk } pvStrButton = self.pvStrButton = Button(pvSysDataFrame, buttonCnf) pvStrButton.grid(row=_row, columnspan=3, sticky=(E + W)) # toolbar toolbar = self.toolbarframe = Frame(master, name='toolbar') toolbar.pack(fill=BOTH) self.QUIT = Button(toolbar, text='Quit', command=self._quit) self.QUIT.pack(side=RIGHT) self.SAVE = Button(toolbar, text='Save', command=self._save) self.SAVE.pack(side=RIGHT) self.LOAD = Button(toolbar, text='Load', command=self._load) self.LOAD.pack(side=RIGHT) self.RESET = Button(toolbar, text='Reset', command=self._reset) self.RESET.pack(side=RIGHT) self.UPDATE = Button(toolbar, text='Update', command=self._update) self.UPDATE.pack(side=RIGHT) self.HELP = Button(toolbar, text='Help', command=self._help) self.HELP.pack(side=RIGHT) self.MESSAGE = Message(toolbar, textvariable=self.msgtext, width=500, fg='red') self.MESSAGE.pack(side=LEFT)
def __init__(self, master, variable, anchor=W, bordercolor=None, borderwidth=1, padx=0, pady=0, background=None, foreground=None, font=None, row_num=0, col_num=0, table=None, width=100, text_to_img=None): Cell.__init__(self, master, background=background, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=borderwidth, bd=0) self.background = background self.text_to_img = text_to_img self.variable = variable self.row_num = row_num self.table = table def change_var(*args): try: if self.text_to_img[self.variable.get()]: #print(self.variable.get()) bg = background fg = foreground if self._message_widget: bg = self._message_widget.cget('background') fg = self._message_widget.cget('foreground') self._message_widget.pack_forget() self._message_widget = Label( self, width=width, background=bg, foreground=fg, image=self.text_to_img[self.variable.get()]) self._message_widget.pack(expand=True, padx=padx, pady=pady, anchor=anchor) self._message_widget.bind( '<Button-1>', lambda event, row=self.row_num, table=self.table: cell_selected(event, table, row)) except KeyError as e: pass return if text_to_img: variable.trace('w', change_var) self._message_widget = Message(self, width=width, textvariable=variable, font=font, background=background, foreground=foreground) self._message_widget.pack(expand=True, padx=padx, pady=pady, anchor=anchor) self.bind('<Button-1>', lambda event, row=row_num, table=table: cell_selected( event, table, row)) self._message_widget.bind('<Button-1>', lambda event, row=row_num, table=table: cell_selected(event, table, row))
# De message widget is hetzelfde als het Label maar biedt meer flexibiliteit voor text from Tkinter import Tk, Message master = Tk() whatever_you_do = "Whatever you do will be insignificant, but it is very important that you do it.\n(Mahatma Gandhi)" msg = Message(master, text=whatever_you_do) msg.config(bg='lightgreen', font=('times', 24, 'italic')) msg.pack() master.mainloop() # Alle magelijke opties voor de config van een message widget, kunnen hier teruggevonden worden: # https://www.python-course.eu/tkinter_message_widget.php