def main(): #------------------------------------------------------------------------------ # We are using the same gui_support as VCDAT for possible future integration #------------------------------------------------------------------------------ root = gui_support.root() Pmw.initialise(root) #---------------------------------------------------------------------------- # One time only call to setup the database session #---------------------------------------------------------------------------- root.echoSql = False extraction_controls.call_sessionmaker(root) #---------------------------------------------------------------------------- # Initialize the GUI widgets #---------------------------------------------------------------------------- root.main_frame = GUI_frame(root) #------------------------------------------------------------------------------ # Display the ESG-CET world image in the background and the copyright #------------------------------------------------------------------------------ root.canvas = Tkinter.Frame(root.pane2.pane('EditPaneTop')) root.canvas.pack(side='top', fill='both', expand=1) txtFont = tkFont.Font(root, family=pub_controls.tab_font_type, size=pub_controls.tab_font_size) copywrite_text = "\nPublisher software version %s @ copyright LLNL/PCMDI\nEarth System Grid Center for Enabling Technologies, funded by the U.S. Department of Energy" % root.Version root.text = Tkinter.Label(root.canvas, text=copywrite_text, font=txtFont, bg="white") root.text.pack(side='top', fill='both', expand=1) img = Tkinter.PhotoImage(file=esg_bg) root.canvas_img = Tkinter.Label(root.canvas, image=img, background="white") root.canvas_img.image = img root.canvas_img.pack(side='top', fill='both', expand=1) #------------------------------------------------------------------------------ # Redirect stderr and stdout to the output windows located in the bottom_right # pane (i.e., "Output" and "Error") # # INFO messages are sent to the "Output" window -- that is, stdout # # WARNING, ERROR, DEBUG, CRITICAL, and Exception messages are sent to # the "Error" window -- that is, stderr # # Note: we distinguish between what is standard out and standard error, # then display the appropriate window to view the text #------------------------------------------------------------------------------ sys.stdout = pub_controls.standard_out(root) sys.stderr = pub_controls.standard_err(root) #---------------------------------------------------------------------------- # Log INFO messages to stdout and display the output to the "Output" window #---------------------------------------------------------------------------- inf = logging.StreamHandler(sys.stdout) inf.setLevel(logging.INFO) logging.getLogger('Info').addHandler(inf) #---------------------------------------------------------------------------- # Log WARNING messages to stderr and display the output to the "Error" window #---------------------------------------------------------------------------- wrn = logging.StreamHandler(sys.stderr) wrn.setLevel(logging.WARNING) logging.getLogger('Warning').addHandler(wrn) #---------------------------------------------------------------------------- # Log ERROR messages to stderr and display the output to the "Error" window #---------------------------------------------------------------------------- err = logging.StreamHandler(sys.stderr) err.setLevel(logging.ERROR) logging.getLogger('Error').addHandler(err) #---------------------------------------------------------------------------- # Log DEBUG messages to stderr and display the output to the "Error" window #---------------------------------------------------------------------------- dbg = logging.StreamHandler(sys.stderr) dbg.setLevel(logging.DEBUG) logging.getLogger('Debug').addHandler(dbg) #---------------------------------------------------------------------------- # Log CRITICAL messages to stderr and display the output to the "Error" window #---------------------------------------------------------------------------- crt = logging.StreamHandler(sys.stderr) crt.setLevel(logging.CRITICAL) logging.getLogger('Critical').addHandler(crt) #---------------------------------------------------------------------------- # Log Exception messages to stderr and display the output to the "Error" window #---------------------------------------------------------------------------- exc = logging.StreamHandler(sys.stderr) exc.setLevel(logging.ERROR) logging.getLogger('Exception').addHandler(exc) #---------------------------------------------------------------------------- # Test the message print commands from logging --- the below lines are # showing examples of how to use Python logging for message sending #---------------------------------------------------------------------------- #debug("%d: This is the Debug Test" % logging.DEBUG) #info("%d: This is the Info Test" % logging.INFO) #warning("%d: This is Warning Test" % logging.WARNING) #error("%d: This is the Error Test" % logging.ERROR) #critical("%d: This is the Critical Test" % logging.CRITICAL) #exception("%d: This is the Exception (NotSet) Test" % logging.NOTSET) #--------------------------------------------------------------------- # View the GUI on the screen. #--------------------------------------------------------------------- root.deiconify() root.update() root.lift() #--------------------------------------------------------------------- # Enter the Tkinter main event loop #--------------------------------------------------------------------- root.mainloop()
def __init__(self, master, r, c): self.master = master self.initialization = False self.sm = Frame(self.master, padx=4, pady=4, bd=2, relief='sunken') self.sm.grid(row=r, column=c, sticky=N + S + W + E) ##Create Fonts self.title = tkFont.Font(family='Helvetica', size=25, weight='bold') self.heading = tkFont.Font(family='Helvetica', size=18, weight='bold') self.content = tkFont.Font(family='Helvetica', size=12, weight='bold') ##Home Button self.homeButton = Button(self.sm, text="HOME", fg="black", bg="blue", height=6, width=16, command=self.jogHome) self.homeButton.grid(row=0, column=0, rowspan=2, padx=30, pady=4) self.homeComplete = 0 ##Start/Stop Controls self.StartPushSmall = Image.open("StartPushSmall.png").convert("RGB") self.StartPushSmall = self.StartPushSmall.resize((125, 108), Image.ANTIALIAS) self.StartPushSmallDisplay = ImageTk.PhotoImage(self.StartPushSmall) self.bigStart = Button(self.sm, image=self.StartPushSmallDisplay, height=108, width=125, command=self.makeLysate) self.bigStart.image = self.StartPushSmallDisplay self.bigStart.grid(row=2, column=0, rowspan=2, padx=30, pady=4) #self.bigStart.pack self.StopPushSmall = Image.open("StopPushSmall.png").convert("RGB") self.StopPushSmall = self.StopPushSmall.resize((125, 108), Image.ANTIALIAS) self.StopPushSmallDisplay = ImageTk.PhotoImage(self.StopPushSmall) self.bigStop = Button(self.sm, image=self.StopPushSmallDisplay, height=108, width=125, command=self.stopAll) self.bigStop.grid(row=4, column=0, rowspan=2, padx=30, pady=4) ##Volume Control self.labelv = Label(self.sm, text="Volume Control", padx=4, pady=4, font=self.heading, anchor="center") self.labelv.grid(row=0, column=1, columnspan=4, sticky=S) self.vStart = 1.5 self.vLower = Button(self.sm, text="<", fg="black", bg="gray", height=2, width=7, command=self.vdecrease) self.vLower.grid(row=1, column=1) self.labelvStart = Label(self.sm, text=self.vStart, padx=4, pady=4, font=self.content, anchor="center") self.labelvStart.grid(row=1, column=2, columnspan=2, sticky=N + E + S + W) self.vUpper = Button(self.sm, text=">", fg="black", bg="gray", height=2, width=7, command=self.vincrease) self.vUpper.grid(row=1, column=4) self.vSet = Button(self.sm, text="Set Total Volume", height=2, width=14, command=self.vset) self.vSet.grid(row=2, column=1, columnspan=2, sticky=W) self.vReset = Button(self.sm, text="Reset to Default", height=2, width=14, command=self.vdefault) self.vReset.grid(row=2, column=3, columnspan=2, sticky=E) ##Cycle Control self.labelc = Label(self.sm, text="Cycles Control", padx=4, pady=2, font=self.heading, anchor="center") self.labelc.grid(row=3, column=1, columnspan=4, sticky=S) self.cStart = 20 self.cLower = Button(self.sm, text="<", fg="black", bg="gray", height=2, width=7, command=self.cdecrease) self.cLower.grid(row=4, column=1) self.labelcStart = Label(self.sm, text=self.cStart, padx=4, pady=4, width=14, font=self.content, anchor="center") self.labelcStart.grid(row=4, column=2, columnspan=2, sticky=N + E + W + S) self.cUpper = Button(self.sm, text=">", fg="black", bg="gray", height=2, width=7, command=self.cincrease) self.cUpper.grid(row=4, column=4, sticky=E) self.cSet = Button(self.sm, text="Set Cycle Number", height=2, width=14, command=self.cset) self.cSet.grid(row=5, column=1, columnspan=2, sticky=W) self.cReset = Button(self.sm, text="Reset to Default", height=2, width=14, command=self.cdefault) self.cReset.grid(row=5, column=3, columnspan=2, sticky=E) #Output Information self.statusLabel = Label(self.sm, text="Status Overview", padx=4, pady=4, font=self.heading, anchor="center") self.statusLabel.grid(row=0, column=5, columnspan=2, sticky=E + S + W) self.cycleCount = 0 self.cCounterLabel = Label(self.sm, text="Current Cycle", padx=4, pady=4, width=31, font=self.content, anchor="center") self.cCounterLabel.grid(row=0, column=5, columnspan=2, sticky=E + S + W) self.cycleCountLabel = Label(self.sm, text=self.cycleCount, padx=4, pady=4, width=31, font=self.content, anchor="center") self.cycleCountLabel.grid(row=1, column=5, columnspan=2, sticky=N + E + W) self.now = "00:00:00" self.timeElapsedLabel = Label(self.sm, text="Time Elapsed", padx=4, pady=4, font=self.content, anchor="center") self.timeElapsedLabel.grid(row=2, column=5, sticky=S + E + W) self.timeUp = Label(self.sm, text=self.now, padx=4, pady=4, font=self.content, anchor="center") self.timeUp.grid(row=3, column=5, sticky=N + E + W) self.remain = "00:00:00" self.timeRemainLabel = Label(self.sm, text="Time Remaining", padx=4, pady=4, font=self.content, anchor="center") self.timeRemainLabel.grid(row=2, column=6, sticky=S + E + W) self.timeDown = Label(self.sm, text=self.remain, padx=4, pady=4, font=self.content, anchor="center") self.timeDown.grid(row=3, column=6, sticky=N + E + W) #Output text widget self.text_box = Text(self.sm, padx=4, pady=4, height=6, width=34, state=DISABLED) self.text_box.grid(row=4, column=5, columnspan=2, rowspan=2) self.scrollb = Scrollbar(self.sm, command=self.text_box.yview) self.scrollb.grid(row=4, column=6, rowspan=2, sticky=N + S + E) self.text_box['yscrollcommand'] = self.scrollb.set sys.stdout = StdRedirector(self.text_box) sys.stderr = StdRedirector(self.text_box) #Parameters stat = MOTOR.getSENSORS(0) self.homeComplete = 0 self.vFinal = 0 self.vCurrent = 0 self.cFinal = 0 self.direction = 0 self.dir_dict = {0: 'cw', 1: 'ccw'}
def __init__(self, master, settings, title): self.master = master self.master.title(title) self.master.geometry("405x180") master.focus_force() self.settings = settings self.frame = None self.obj_lbl = Label(self.master, text="Object Details", font=tkFont.Font(family="Helvetica", size=15)) self.obj_lbl.grid(columnspan=2, row=0, column=0, pady=(5, 10), padx=(7, 0), sticky="w") self.name_lbl = Label(self.master, text="Object Name:") self.name_lbl.grid(row=1, column=0, sticky="e", pady=5) self.name = Entry(self.master, width=40) self.name.grid(row=1, column=1, sticky="w", columnspan=2) self.selected = StringVar() self.selected_lbl = Label(self.master, textvariable=self.selected) self.selected_lbl.grid(row=2, column=0, sticky="e", pady=(5, 0)) self.selected.set("No Object Selected") self.capture_btn = Button(self.master, text="Start Capture", command=self._startCapture, width=20, height=2) self.capture_btn.grid(row=2, column=1, columnspan=2, sticky="e", pady=(5, 0)) self.cancel_btn = Button(self.master, text="Cancel", command=self._cancelObjAdd, width=20, height=2) self.cancel_btn.grid(row=3, column=0, sticky="w", pady=(10, 0), padx=(5, 0)) self.save_btn = Button(self.master, text="Add", command=self._saveObjAdd, width=20, height=2) self.save_btn.grid(row=3, column=1, sticky="e", columnspan=2, pady=(10, 0))
import tkFont button_flag = True def click(): """ respond to the button click """ global button_flag # toggle button colors as a test if button_flag: button1.config(bg="white") button_flag = False else: button1.config(bg="green") button_flag = True root = tk.Tk() times = tkFont.Font(family="Helvetica", size=10, weight=tkFont.BOLD) # create a frame and pack it frame1 = tk.Frame(root, width=2000, height=2000) frame1.pack(fill=None, expand=False) # pick a (small) image file you have in the working directory ... photo1 = tk.PhotoImage(file="rsz_latteart.gif") photo2 = tk.PhotoImage(file="rsz_exps.gif") # create the image button, image is above (top) the optional text button1 = tk.Button(frame1, compound=tk.LEFT, width=250, height=150, image=photo1, text="Produženi espresso", fg='black', font=times, bg="#C0C0C0", command=click) button1.pack(side=tk.TOP, padx=2, pady=2) # save the button's image from garbage collection (needed?) button1.image = photo1 button2 = tk.Button(frame1, compound=tk.LEFT, width=250, height=150, image=photo2, text="Produženi espresso sa mlekom", fg='black', wraplength=150, font=times, bg="#C0C0C0", command=click) button2.pack(padx=2, pady=2)
def __init__(self): self.root = Tkinter.Tk() self.root.title(self.title) #窗口面板,用4个面板布局 self.frame = [ Tkinter.Frame(), Tkinter.Frame(), Tkinter.Frame(), Tkinter.Frame(), Tkinter.Frame(), Tkinter.Frame() ] #显示消息Text右边的滚动条 self.chatTextScrollBar = Tkinter.Scrollbar(self.frame[0]) self.chatTextScrollBar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y) #显示消息Text,并绑定上面的滚动条 ft = tkFont.Font(family='Fixdsys', size=11) #root = Tk() #self.chatText = Tkinter.Listbox(self.frame[0],width=70,height=18,font=ft) self.chatText = Tkinter.Text(self.frame[0], width=70, height=25, font=ft) self.chatText['yscrollcommand'] = self.chatTextScrollBar.set self.chatText.pack(expand=1, fill=Tkinter.BOTH) #self.chatText(root,warplength=80).pack() self.chatTextScrollBar['command'] = self.chatText.yview() self.frame[0].pack(expand=1, fill=Tkinter.BOTH) label = Tkinter.Label(self.frame[1], height=2, text="指令:") label.pack(fill=Tkinter.BOTH, side=Tkinter.LEFT) #label.pack(fill=Tkinter.BOTH,3,1) self.frame[1].pack(expand=1, fill=Tkinter.BOTH) #self.inputTextScrollBar = Tkinter.Scrollbar(self.frame[2]) #self.inputTextScrollBar.pack(side=Tkinter.RIGHT,fill=Tkinter.Y) #ft = tkFont.Font(family='Fixdsys',size=11) #self.chatText1 = Tkinter.Listbox(self.frame[2],width=70,height=2,font=ft) #self.chatText1['yscrollcommand'] = self.chatTextScrollBar.set #self.chatText1.pack(expand=1,fill=Tkinter.BOTH) #self.chatTextScrollBar['command'] = self.chatText.yview() #self.frame[2].pack(expand=1,fill=Tkinter.BOTH) ft = tkFont.Font(family='Fixdsys', size=11) self.chatText1 = Tkinter.Listbox(self.frame[2], width=70, height=2, font=ft) self.chatText1.pack(expand=1, fill=Tkinter.BOTH) self.frame[2].pack(expand=1, fill=Tkinter.BOTH) #标签,分开消息显示Text和消息输入Text label = Tkinter.Label(self.frame[3], height=2, text="问句:") label.pack(fill=Tkinter.BOTH, side=Tkinter.LEFT) #label.pack(fill=Tkinter.BOTH,3,1) self.frame[3].pack(expand=1, fill=Tkinter.BOTH) #self.frame[1].LabelText="answer" #输入消息Text的滚动条 self.inputTextScrollBar = Tkinter.Scrollbar(self.frame[4]) self.inputTextScrollBar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y) #输入消息Text,并与滚动条绑定 ft = tkFont.Font(family='Fixdsys', size=11) self.inputText = Tkinter.Text(self.frame[4], width=70, height=5, font=ft) self.inputText['yscrollcommand'] = self.inputTextScrollBar.set self.inputText.pack(expand=1, fill=Tkinter.BOTH) self.inputTextScrollBar['command'] = self.chatText.yview() self.frame[4].pack(expand=1, fill=Tkinter.BOTH) #发送消息按钮 self.sendButton = Tkinter.Button(self.frame[5], text=' 发 送 ', width=10, command=self.sendMessage) #self.sendButton.pack(expand=1,side=Tkinter.BOTTOM and Tkinter.LEFT,padx=15,pady=8) self.sendButton.pack(expand=1, side=Tkinter.LEFT, padx=15, pady=8) #关闭按钮 self.closeButton = Tkinter.Button(self.frame[5], text=' 关 闭 ', width=10, command=self.close) self.closeButton.pack(expand=1, side=Tkinter.RIGHT, padx=15, pady=8) self.flashButton = Tkinter.Button(self.frame[5], text=' 刷新 ', width=10, command=self.flash) self.flashButton.pack(expand=1, side=Tkinter.RIGHT, padx=15, pady=8) self.frame[5].pack(expand=1, fill=Tkinter.BOTH)
# GUI GENERATION PART ************************************************************************ root = tk.Tk() # Add a grid content = ttk.Frame(root) content.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S), pady=10, padx=10) #Font definition #helv36 = tkFont.Font(family='Helvetica', size=36, weight=tkFont.BOLD) helv26 = tkFont.Font(family='Helvetica', size=26, weight=tkFont.BOLD) label = tk.Label(content, text=' Mister Mess Robot ', font=helv26, fg="blue") label.grid(column=0, row=1, columnspan=2) #We create the buttons for the StopPoints for StopPoint_num in range(0, len(StopPoints), 2): bt_StopPoint = tk.Button(content, height=1, width=19, font=helv26, text=StopPoints[StopPoint_num][i_StopPoint_name], command=lambda StopPoint_num=StopPoint_num: goto_StopPoint(StopPoint_num)) bt_StopPoint.grid(column=0, row=2 + StopPoint_num)
def __init__(self, CodeClass): # Configure FoxDot's namespace to include the editor CodeClass.namespace['FoxDot'] = self CodeClass.namespace['Player'].widget = self self.version = this_version = CodeClass.namespace['__version__'] pypi_version = get_pypi_version() def check_versions(): if pypi_version is not None and VersionNumber( pypi_version) > VersionNumber(this_version): tkMessageBox.showinfo( "New version available", "There is a new version of FoxDot available from PyPI. Upgrade by going to your command prompt and running:\n\npip install FoxDot --upgrade" ) return # Used for docstring prompt self.namespace = CodeClass.namespace # Set up master widget self.root = Tk(className='FoxDot') self.root.title( "FoxDot v{} - Live Coding with Python and SuperCollider".format( this_version)) self.root.rowconfigure(0, weight=1) # Text box self.root.rowconfigure(1, weight=0) # Separator self.root.rowconfigure(2, weight=0) # Console self.root.grid_columnconfigure(0, weight=0) # line numbers self.root.grid_columnconfigure(1, weight=1) # Text boxes self.root.protocol("WM_DELETE_WINDOW", self.kill) # Track whether user wants transparent background self.transparent = BooleanVar() self.transparent.set(False) self.using_alpha = USE_ALPHA # Boolean for connection self.listening_for_connections = BooleanVar() self.listening_for_connections.set(False) # Boolean for showing auto-complete prompt self.show_prompt = BooleanVar() self.show_prompt.set(True) # --- Set icon try: # Use .ico file by default self.root.iconbitmap(FOXDOT_ICON) except TclError: # Use .gif if necessary self.root.tk.call('wm', 'iconphoto', self.root._w, PhotoImage(file=FOXDOT_ICON_GIF)) # --- Setup font system_fonts = tkFont.families() self.codefont = "CodeFont" # name for font if self.default_font not in system_fonts: if SYSTEM == WINDOWS and "Consolas" in system_fonts: self.default_font = "Consolas" elif SYSTEM == MAC_OS and "Monaco" in system_fonts: self.default_font = "Monaco" elif "Courier New" in system_fonts: self.default_font = "Courier New" else: self.console_font = self.codefont = self.default_font = "TkFixedFont" if self.codefont == "CodeFont": self.font = tkFont.Font(font=(self.default_font, 12), name=self.codefont) self.font.configure(family=self.default_font) self.console_font = (self.default_font, 12) self.help_key = "K" if SYSTEM == MAC_OS else "H" # --- start create menu self.menu = MenuBar(self, visible=MENU_ON_STARTUP) self.popup = PopupMenu(self) # Create y-axis scrollbar self.y_scroll = Scrollbar(self.root) self.y_scroll.grid(row=0, column=2, sticky='nsew') # Create text box for code self.text = ThreadedText(self.root, padx=5, pady=5, bg=colour_map['background'], fg=colour_map['plaintext'], insertbackground="White", font=self.codefont, yscrollcommand=self.y_scroll.set, width=100, height=20, bd=0, undo=True, autoseparators=True, maxundo=50) self.text.grid(row=0, column=1, sticky="nsew") self.y_scroll.config(command=self.text.yview) self.text.focus_set() self.text_as_string = "" # Create box for line numbers self.linenumbers = LineNumbers(self, width=50, bg=colour_map['background'], bd=0, highlightthickness=0) self.linenumbers.grid(row=0, column=0, sticky='nsew') # Docstring prompt label self.prompt = TextPrompt(self) # Key bindings (Use command key on Mac) ctrl = "Command" if SYSTEM == MAC_OS else "Control" alt = "Option" if SYSTEM == MAC_OS else "Alt" self.text.bind("<<Modified>>", self.on_text_modified) self.text.bind("<Return>", self.newline) self.text.bind("<BackSpace>", self.backspace) self.text.bind("<Delete>", self.delete) self.text.bind("<Tab>", self.tab) self.text.bind("<Key>", self.keypress) self.text.bind("<Button-{}>".format(2 if SYSTEM == MAC_OS else 3), self.show_popup) self.text.bind("<{}-BackSpace>".format(ctrl), self.delete_word) self.text.bind("<{}-Delete>".format(ctrl), self.delete_next_word) self.text.bind("<{}-Return>".format(ctrl), self.exec_block) self.text.bind("<{}-Return>".format(alt), self.exec_line) # Directional movement self.text.bind("<Up>", self.key_up) self.text.bind("<Down>", self.key_down) self.text.bind("<{}-Left>".format(ctrl), self.move_word_left) self.text.bind("<{}-Right>".format(ctrl), self.move_word_right) self.text.bind("<{}-Shift-Right>".format(ctrl), self.select_word_right) self.text.bind("<{}-Shift-Left>".format(ctrl), self.select_word_left) self.text.bind("<Alt_L>", lambda event: "break") self.text.bind("<Alt-n>", lambda event: "break") # Fixes a MacOS tilde bug. self.text.bind("<{}-a>".format(ctrl), self.select_all) self.text.bind("<{}-d>".format(ctrl), self.duplicate_line) self.text.bind("<{}-period>".format(ctrl), self.killall) self.text.bind("<Alt-period>".format(ctrl), self.releaseNodes) self.text.bind("<{}-c>".format(ctrl), self.edit_copy) self.text.bind("<{}-x>".format(ctrl), self.edit_cut) self.text.bind("<{}-v>".format(ctrl), self.edit_paste) self.text.bind("<{}-bracketright>".format(ctrl), self.indent) self.text.bind("<{}-bracketleft>".format(ctrl), self.unindent) self.text.bind("<{}-equal>".format(ctrl), self.zoom_in) self.text.bind("<{}-minus>".format(ctrl), self.zoom_out) self.text.bind("<{}-z>".format(ctrl), self.undo) self.text.bind("<{}-y>".format(ctrl), self.redo) self.text.bind("<{}-s>".format(ctrl), self.save) self.text.bind("<{}-o>".format(ctrl), self.openfile) self.text.bind("<{}-n>".format(ctrl), self.newfile) self.text.bind("<{}-m>".format(ctrl), self.toggle_menu) self.text.bind( "<{}-l>".format(ctrl), lambda event: self.insert_char(u"\u03BB")) # insert lambda self.text.bind("<{}-t>".format(ctrl), lambda event: self.insert_char("~")) self.text.bind("<{}-{}>".format(ctrl, self.help_key.lower()), self.help) # Number pad for event in [ "KP_Right", "KP_Left", "KP_Up", "KP_Down", "KP_Delete", "KP_Home", "KP_End", "KP_Next", "KP_Prior" ]: try: event1 = "<{}>".format(event) event2 = "<{}-{}>".format(ctrl, event) event3 = "<{}-{}>".format("Shift", event) event4 = "<{}-{}-{}>".format("Shift", ctrl, event) event5 = "<{}-{}-{}>".format(ctrl, "Shift", event) self.text.bind( event1, partial(lambda *args: self.text.event_generate(args[0]), event1.replace("KP_", ""))) self.text.bind( event2, partial(lambda *args: self.text.event_generate(args[0]), event2.replace("KP_", ""))) self.text.bind( event3, partial(lambda *args: self.text.event_generate(args[0]), event3.replace("KP_", ""))) self.text.bind( event4, partial(lambda *args: self.text.event_generate(args[0]), event4.replace("KP_", ""))) self.text.bind( event5, partial(lambda *args: self.text.event_generate(args[0]), event5.replace("KP_", ""))) except TclError: pass try: self.text.bind("<KP_Enter>", self.newline) except TclError: pass # Toggle console button keybind try: self.text.bind("<{}-#>".format(ctrl), self.toggle_console) self.toggle_key = "#" except: self.text.bind("<{}-G>".format(ctrl), self.toggle_console) self.toggle_key = "G" # Save feature variabes self.saved = False self.file = None self.filename = None # --- define bracket behaviour self.bracketHandler = BracketHandler(self) # Set tag names and config for specific colours for tier in tag_weights: for tag_name in tier: self.text.tag_config(tag_name, foreground=colour_map[tag_name]) # --- Create console self.console = console(self) self.console_visible = True sys.stdout = self.console self.root.bind("<Button-1>", self.mouse_press) # Store original location of cursor self.origin = "origin" self.text.mark_set(self.origin, INSERT) self.text.mark_gravity(self.origin, LEFT) # Say Hello to the user def hello(): if SYSTEM == MAC_OS: ctrl = "Cmd" else: ctrl = "Ctrl" # with open(FOXDOT_HELLO) as f: # hello = f.read() # print() # print(hello) # print() hello = "Welcome to FoxDot! Press {}+{} for help.".format( ctrl, self.help_key) print(hello) print("-" * len(hello)) # Ask after widget loaded self.root.after(50, hello) # Check temporary file def recover_work(): with open(FOXDOT_TEMP_FILE) as f: text = f.read() if len(text): loading = tkMessageBox.askyesno( "Load unsaved work?", "Your code wasn't saved last time you used FoxDot, do you want to load any unsaved work?" ) self.root.update() if loading: self.set_all(text) else: self.clear_temp_file() self.text_as_string = self.get_all() # Execute startup file return execute.load_startup_file() # Check online if a new version if available self.root.after(90, check_versions) # Ask after widget loaded if RECOVER_WORK: self.root.after(100, recover_work) # Check transparency on startup if TRANSPARENT_ON_STARTUP: self.transparent.set(True) self.root.after(100, self.toggle_transparency)
def __init__(self): self.root = Tk() # Create main window self.root.geometry("1280x400") # Set defualt window size self.root.title("Plotify") # Give it a spunky name Grid.rowconfigure( self.root, 0, weight=1) # Assign a single resizeable row to the window Grid.columnconfigure( self.root, 0, weight=1) # Assign a single resizeable column to the window self.frame = Frame( self.root) # Create a single frame inside main window self.frame.grid( row=0, column=0, sticky=N + S + E + W) # Sticky = frame will expand to fill all corners of the window ## Configure rows and columns inside frame ## Grid.rowconfigure(self.frame, 0, weight=0, minsize=25) # Upper padding row Grid.rowconfigure(self.frame, 1, weight=0) # Directory and search box row Grid.rowconfigure(self.frame, 2, weight=0, minsize=25) # Padding row Grid.rowconfigure(self.frame, 3, weight=0) # Pane labels row Grid.rowconfigure(self.frame, 4, weight=1) # Variable panes first row Grid.rowconfigure(self.frame, 5, weight=0) # Variable buttons row 1 Grid.rowconfigure(self.frame, 6, weight=0) # Variable buttons row 2 Grid.rowconfigure(self.frame, 7, weight=0) # Variable buttons row 3 Grid.rowconfigure(self.frame, 8, weight=0, pad=15) # Variable buttons row 4 Grid.rowconfigure(self.frame, 9, weight=0, pad=15) # Variable buttons row 5 Grid.rowconfigure(self.frame, 10, weight=0) # Variable buttons row 6 Grid.rowconfigure(self.frame, 11, weight=1) # Variable panes last row Grid.rowconfigure(self.frame, 12, weight=0, minsize=25) # Padding row Grid.rowconfigure(self.frame, 13, weight=0) # Bottom button row Grid.rowconfigure(self.frame, 14, weight=0, minsize=25) # Padding row Grid.columnconfigure(self.frame, 0, weight=0, minsize=25) # Left padding column Grid.columnconfigure(self.frame, 1, weight=1, minsize=375) # Navigation pane column Grid.columnconfigure(self.frame, 2, weight=0) # Navigation pane scrollbar column Grid.columnconfigure(self.frame, 3, weight=0, minsize=25) # Padding column Grid.columnconfigure(self.frame, 4, weight=1) # Variable search pane column Grid.columnconfigure(self.frame, 5, weight=0) # Variable search pane scrollbar column Grid.columnconfigure(self.frame, 6, weight=0, pad=30) # Variable plot button column Grid.columnconfigure(self.frame, 7, weight=1) # Variable plot pane column Grid.columnconfigure(self.frame, 8, weight=0) # Variable plot pane scrollbar column Grid.columnconfigure(self.frame, 9, weight=0, minsize=25) # Right padding column ''' numColmns = 4 numRows = 10 epx = 5 epy = 5 ipx = 5 ipy = 5 ''' ## Create Widgets ## path = os.getcwd() self.navigationBar = Label( self.frame, text=path ) # Navigation bar displays current directory we are working from self.navigationPane = Listbox( self.frame ) # Create navigation pane listbox & corresponding scrollbar self.navigationBar_scroll = Scrollbar(self.frame, orient=VERTICAL) self.navigationPane.config( yscrollcommand=self.navigationBar_scroll.set) self.navigationBar_scroll.config(command=self.navigationPane.yview) self.varSearchPane = Listbox( self.frame, selectmode=MULTIPLE ) # Create variable search pane & corresponding scrollbar self.varSearchPane_scroll = Scrollbar(self.frame, orient=VERTICAL) self.varSearchLabel = Label(self.frame, text="Search Results") self.varSearchPane.config(yscrollcommand=self.varSearchPane_scroll.set) self.varSearchPane_scroll.config(command=self.varSearchPane.yview) self.varPlotPane = Listbox( self.frame, selectmode=EXTENDED ) # Create variable plot pane & corresponding scrollbar self.varPlotPane_scroll = Scrollbar(self.frame, orient=VERTICAL) self.varPlotLabel = Label(self.frame, text="Variables to Plot") self.varPlotPane.config(yscrollcommand=self.varPlotPane_scroll.set) self.varPlotPane_scroll.config(command=self.varPlotPane.yview) self.variableSearchEntryLabel = Label(self.frame, text="Search:") self.variableSearchEntry = Entry(self.frame) ## self.variableSearchEntry.insert(0, "Variable Search Box") self.arrowFont = tkFont.Font(family='Helvetica', size=17, weight='bold') self.pushLeftBtn = Button(self.frame, text="◄", command=self.pushLeftBtnCMD, font=self.arrowFont) self.pushRightBtn = Button(self.frame, text="►", command=self.pushRightBtnCMD, font=self.arrowFont) self.plotBtn = Button(self.frame, text="Plot!", command=self.generatePlot) ## Place widgets in the frame ## self.navigationBar.grid(row=1, column=1) self.navigationPane.grid(row=2, column=1, rowspan=10, sticky=N + S + E + W) self.navigationBar_scroll.grid(row=2, column=2, rowspan=10, sticky=N + S + E + W) self.varSearchLabel.grid(row=3, column=4, sticky=N + S + E + W) self.varSearchPane.grid(row=4, column=4, rowspan=8, sticky=N + S + E + W) self.varSearchPane_scroll.grid(row=4, column=5, rowspan=8, sticky=N + S + E + W) self.varPlotLabel.grid(row=3, column=7, sticky=N + S + E + W) self.varPlotPane.grid(row=4, column=7, rowspan=8, sticky=N + S + E + W) self.varPlotPane_scroll.grid(row=4, column=8, rowspan=8, sticky=N + S + E + W) self.variableSearchEntryLabel.grid(row=1, column=4, sticky=W) self.variableSearchEntry.grid(row=2, column=4, columnspan=5, sticky=N + S + E + W) self.pushLeftBtn.grid(row=7, column=6) self.pushRightBtn.grid(row=8, column=6) self.plotBtn.grid(row=13, column=6) ## Bind widget events to functions ## self.variableSearchEntry.bind("<KeyRelease>", self.updateVarSearchPane) self.navigationPane.bind("<<ListboxSelect>>", self.getVarsFromFile) self.getFileList( ) #Populate navigation pane with all data files in current directory ## Run GUI instance Mainloop ## ## self.root.after(1000, self.updateVarSearchPane()) self.count = 0 self.variables = [] #Initilialize variable list self.root.mainloop()
def DrawObject(self, drawing, showGG=0): self.dc = drawing if showGG and self.semanticObject: self.drawGGLabel(drawing) h = drawing.create_oval(self.translate([36.0, 141.0, 36.0, 141.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([76.0, 141.0, 76.0, 141.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([116.0, 141.0, 116.0, 141.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([156.0, 141.0, 156.0, 141.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([1.0, 69.0, 1.0, 69.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([1.0, 41.0, 1.0, 41.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([1.0, 96.0, 1.0, 96.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([1.0, 121.0, 1.0, 121.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([191.0, 69.0, 191.0, 69.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([191.0, 41.0, 191.0, 41.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([191.0, 96.0, 191.0, 96.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([191.0, 121.0, 191.0, 121.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([156.0, 1.0, 156.0, 1.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([116.0, 1.0, 116.0, 1.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([76.0, 1.0, 76.0, 1.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_oval(self.translate([36.0, 1.0, 36.0, 1.0]), tags=(self.tag, 'connector'), outline='', fill='') self.connectors.append(h) h = drawing.create_rectangle(self.translate([1.0, 1.0, 191.0, 21.0]), tags=self.tag, stipple='', width=1, outline='black', fill='yellow') self.gf1 = GraphicalForm(drawing, h, "gf1") self.graphForms.append(self.gf1) h = drawing.create_rectangle(self.translate([1.0, 21.0, 191.0, 141.0]), tags=self.tag, stipple='', width=1, outline='black', fill='#f8f8f8') self.gf3 = GraphicalForm(drawing, h, "gf3") self.graphForms.append(self.gf3) if self.semanticObject: drawText = self.semanticObject.display.toString() else: drawText = "<display>" font = tkFont.Font(family='Helvetica', size=12, weight='normal', slant='roman', underline=0) h = drawing.create_text(self.translate([2.0, 24.0, 2.0, 12.0])[:2], tags=self.tag, font=font, fill='blue1', anchor='nw', text=drawText, width='0', justify='left', stipple='') self.attr_display["display"] = h self.gf4 = GraphicalForm(drawing, h, 'gf4', fontObject=font) self.graphForms.append(self.gf4) font = tkFont.Font(family='Helvetica', size=9, weight='normal', slant='roman', underline=0) h = drawing.create_text(self.translate([188.0, 5.0, 188.0, 9.0])[:2], tags=self.tag, font=font, fill='black', anchor='ne', text='<<Abstract>>', width='0', justify='left', stipple='') self.gf46 = GraphicalForm(drawing, h, 'gf46', fontObject=font) self.graphForms.append(self.gf46) if self.semanticObject: drawText = self.semanticObject.name.toString() else: drawText = "<name>" font = tkFont.Font(family='Helvetica', size=12, weight='bold', slant='roman', underline=0) h = drawing.create_text(self.translate([5.0, 2.0, 5.0, 12.0])[:2], tags=self.tag, font=font, fill='black', anchor='nw', text=drawText, width='0', justify='left', stipple='') self.attr_display["name"] = h self.gf63 = GraphicalForm(drawing, h, 'gf63', fontObject=font) self.graphForms.append(self.gf63)
def _font(fname="微软雅黑", size=12, bold=tkFont.NORMAL): """设置字体""" ft = tkFont.Font(family=fname, size=size, weight=bold) return ft
def __init__(self, main, root=None) : if root==None: root=Tk() root.geometry('600x800+350+70') self.root = root self.top = root self.root.title("BoomstraDam") self.main = main #self.root.option_add("*Font", "TSCu_Paranar 10") # variables self.current_white_player=IntVar() # (computer, human player, remote player) self.current_black_player=IntVar() # (computer, human player, remote player) self.current_player=IntVar() # (computer, human player, remote player) , redundant to simplifly coding self.current_color_on_move=IntVar() # current color state self.auto_move = IntVar() # auto move and capture for human player self.invert_board = IntVar() # turn the board 180 degrees self.status_display = StringVar() # to show move and lost/win status self.phase=IntVar() self.notation_display = StringVar() # to display the notation of the game self.white_numbers_display = StringVar() # to display the number of men and king self.black_numbers_display =StringVar() self.sound_mode = dc.SOUND_OFF # reflects the sound mode self.WhitePlayer = StringVar() #the info for the game self.BlackPlayer = StringVar() self.Result = StringVar() self.Date = StringVar() self.Round = StringVar() self.Event = StringVar() self.result_text = StringVar() self.myFont = tkFont.Font(family="helvetica", weight="bold", size=9) # frames # self.frame_overall_frame = Frame(self.root, relief = GROOVE, bd =4) self.info_frame =Frame(self.root, bd=3, relief=GROOVE) self.buttonbar = Frame(self.root)#, bd=3, relief=GROOVE) self.frame_remaining_layout = Frame(self.root ) self.frame_notation_frame = Frame(self.root) self.frame_right_hand = Frame(self.frame_remaining_layout) self.frame_left_hand = Frame(self.frame_remaining_layout) self.board_frame = Frame(self.frame_remaining_layout, height=10*self.HEIGHT, width=10*self.WIDTH, bd=4, relief=RAISED) self.current_player_frame = Frame(self.frame_right_hand) # key bindings self.root.bind("<Escape>", self.esc_proc) self.root.protocol("WM_DELETE_WINDOW", self.end_proc) self.root.bind("<space>", self.move_now) self.root.bind("<Left>", self.main.left_arrow_clicked) self.root.bind("<Right>", self.main.right_arrow_clicked) self.root.bind("<Up>", self.main.up_arrow_clicked) self.root.bind("<Down>", self.main.down_arrow_clicked) self.root.bind("<Control-Left>", self.main.control_left_arrow_clicked) self.root.bind("<Control-Right>", self.main.control_right_arrow_clicked) self.root.bind("<Control-Up>", self.main.control_up_arrow_clicked) self.root.bind("<Control-Down>", self.main.control_down_arrow_clicked) self.root.bind("<Next>", self.main.page_down_clicked) self.root.bind("<Prior>", self.main.page_up_clicked) self.root.bind("n",self.main.stand.next_line) self.root.bind("p",self.main.stand.prev_line) # define the draught board itself self.dv=PhotoImage(file="/home/feike/BoomstraDam/images/ds.gif") self.ws=PhotoImage(file="/home/feike/BoomstraDam/images/ws.gif") self.wd=PhotoImage(file="/home/feike/BoomstraDam/images/wd.gif") self.zs=PhotoImage(file="/home/feike/BoomstraDam/images/zs.gif") self.zd=PhotoImage(file="/home/feike/BoomstraDam/images/zd.gif") self.fdv=PhotoImage(file="/home/feike/BoomstraDam/images/fds.gif") self.fws=PhotoImage(file="/home/feike/BoomstraDam/images/fws.gif") self.fwd=PhotoImage(file="/home/feike/BoomstraDam/images/fwd.gif") self.fzs=PhotoImage(file="/home/feike/BoomstraDam/images/fzs.gif") self.fzd=PhotoImage(file="/home/feike/BoomstraDam/images/fzd.gif") self.board_frame.columnconfigure(0,minsize=0, pad=0) self.board_frame.columnconfigure(1,minsize=0, pad=0) self.board_frame.columnconfigure(2,minsize=0, pad=0) self.board_frame.columnconfigure(3,minsize=0, pad=0) self.board_frame.columnconfigure(4,minsize=0, pad=0) self.board_frame.columnconfigure(5,minsize=0, pad=0) self.board_frame.columnconfigure(6,minsize=0, pad=0) self.board_frame.columnconfigure(7,minsize=0, pad=0) self.board_frame.columnconfigure(8,minsize=0, pad=0) self.board_frame.columnconfigure(9,minsize=0, pad=0) self.board_frame.rowconfigure(0, minsize=0, pad=0) self.board_frame.rowconfigure(1, minsize=0, pad=0) self.board_frame.rowconfigure(2, minsize=0, pad=0) self.board_frame.rowconfigure(3, minsize=0, pad=0) self.board_frame.rowconfigure(4, minsize=0, pad=0) self.board_frame.rowconfigure(5, minsize=0, pad=0) self.board_frame.rowconfigure(6, minsize=0, pad=0) self.board_frame.rowconfigure(7, minsize=0, pad=0) self.board_frame.rowconfigure(8, minsize=0, pad=0) self.board_frame.rowconfigure(9, minsize=0, pad=0) self.c=[] for i in range(51): self.c.append(Canvas(self.board_frame, height=self.HEIGHT, width=self.WIDTH, bd=0, selectborderwidth=0, highlightthickness=0)) self.c[i].bind("<Button-1>", self.left_button_pressed) self.c[i].bind("<Button-3>", self.right_button_pressed) self.c[1].grid(row=0, column=1) self.c[2].grid(row=0, column=3) self.c[3].grid(row=0, column=5) self.c[4].grid(row=0, column=7) self.c[5].grid(row=0, column=9) self.c[6].grid(row=1, column=0) self.c[7].grid(row=1, column=2) self.c[8].grid(row=1, column=4) self.c[9].grid(row=1, column=6) self.c[10].grid(row=1, column=8) self.c[11].grid(row=2, column=1) self.c[12].grid(row=2, column=3) self.c[13].grid(row=2, column=5) self.c[14].grid(row=2, column=7) self.c[15].grid(row=2, column=9) self.c[16].grid(row=3, column=0) self.c[17].grid(row=3, column=2) self.c[18].grid(row=3, column=4) self.c[19].grid(row=3, column=6) self.c[20].grid(row=3, column=8) self.c[21].grid(row=4, column=1) self.c[22].grid(row=4, column=3) self.c[23].grid(row=4, column=5) self.c[24].grid(row=4, column=7) self.c[25].grid(row=4, column=9) self.c[26].grid(row=5, column=0) self.c[27].grid(row=5, column=2) self.c[28].grid(row=5, column=4) self.c[29].grid(row=5, column=6) self.c[30].grid(row=5, column=8) self.c[31].grid(row=6, column=1) self.c[32].grid(row=6, column=3) self.c[33].grid(row=6, column=5) self.c[34].grid(row=6, column=7) self.c[35].grid(row=6, column=9) self.c[36].grid(row=7, column=0) self.c[37].grid(row=7, column=2) self.c[38].grid(row=7, column=4) self.c[39].grid(row=7, column=6) self.c[40].grid(row=7, column=8) self.c[41].grid(row=8, column=1) self.c[42].grid(row=8, column=3) self.c[43].grid(row=8, column=5) self.c[44].grid(row=8, column=7) self.c[45].grid(row=8, column=9) self.c[46].grid(row=9, column=0) self.c[47].grid(row=9, column=2) self.c[48].grid(row=9, column=4) self.c[49].grid(row=9, column=6) self.c[50].grid(row=9, column=8) self.image_item=[] for i in range(51): self.image_item.append(self.c[i].create_image(0, 0, image=self.dv, anchor=NW, tags=str(i))) # end of definition of draught board # The other parts of the application interface: toolbar and buttons self.menubar = Menu(self.root) # create a pulldown menu "File", and add it to the menu bar self.filemenu = Menu(self.menubar, tearoff=0) self.filemenu.add_command(label="New Game", command=self.main.new_game_clicked) self.filemenu.add_command(label="Open Game", command=self.main.file_open_game_clicked) self.filemenu.add_command(label="Save Game", command=self.main.file_save_game_clicked) self.filemenu.add_command(label="Save Doc", command=self.main.file_save_doc_clicked) self.filemenu.add_command(label="Make Records", command=self.main.make_game_records.MakeGameRecords) self.filemenu.add_command(label="Open Stands", command=self.main.stand.get_stand_file) self.filemenu.add_separator() self.filemenu.add_command(label="Exit", command=self.end_proc) self.menubar.add_cascade(label="File", menu=self.filemenu) # create a pulldown menu "Remote", and add it to the menu bar self.remotemenu = Menu(self.menubar, tearoff=0) self.remotemenu.add_command(label="Make Connection", command=self.hello) self.remotemenu.add_command(label="Wait for Connection", command=self.remote_play_mode) self.menubar.add_cascade(label="Remote", menu=self.remotemenu) # create a pulldown menu "Info", and add it to the menu bar self.info_menu = Menu(self.menubar, tearoff=0) self.info_menu.add_command(label="Game Info", command=self.main.Get_Game_Info) self.info_menu.add_command(label="Time Info", command=self.main.Get_Time_Info) self.menubar.add_cascade(label="Info", menu=self.info_menu) # create a pulldown menu "Test", and add it to the menu bar self.test_menu = Menu(self.menubar, tearoff=0) self.test_menu.add_command(label="Eval", command=self.main.eval_mode_clicked) self.test_menu.add_command(label="Anal Time", command=self.main.anal_time_mode_clicked) self.test_menu.add_command(label="Anal Pos d=02", command=self.main.anal_pos_mode_clicked_02) self.test_menu.add_command(label="Anal Pos d=04", command=self.main.anal_pos_mode_clicked_04) self.test_menu.add_command(label="Anal Pos d=06", command=self.main.anal_pos_mode_clicked_06) self.test_menu.add_command(label="Anal Pos d=08", command=self.main.anal_pos_mode_clicked_08) self.test_menu.add_command(label="Anal Pos d=10", command=self.main.anal_pos_mode_clicked_10) self.test_menu.add_command(label="Anal Pos d=12", command=self.main.anal_pos_mode_clicked_12) self.test_menu.add_command(label="Anal Pos d=14", command=self.main.anal_pos_mode_clicked_14) self.menubar.add_cascade(label="Test", menu=self.test_menu) # create a pulldown menu "WalkHash", and add it to the menu bar self.walkhash_menu = Menu(self.menubar, tearoff=0) self.walkhash_menu.add_command(label="Set Depth", command=self.main.set_depth) self.walkhash_menu.add_command(label="Set Threads", command=self.main.set_threads) self.walkhash_menu.add_command(label="Prepare Hash", command=self.main.setup_hash) self.walkhash_menu.add_command(label="Walk Hash", command=self.main.walk_hash_proc) self.walkhash_menu.add_command(label="CEM", command=self.main.CEM) self.menubar.add_cascade(label="Debug", menu=self.walkhash_menu) # create more pulldown menus self.viewmenu = Menu(self.menubar, tearoff=0) self.viewmenu.add_command(label=" Sound -- On", command=self.set_sound_level_on) self.viewmenu.add_command(label=" Sound -- TWO", command=self.set_sound_level_TWO) self.viewmenu.add_command(label="> Sound -- Off", command=self.set_sound_level_off) self.menubar.add_cascade(label="View", menu=self.viewmenu) # a tricky one self.viewmenu = Menu(self.menubar, tearoff=0) live = LiveDraughts() list = live.get_players() index = 0 for players in list: index += 1 self.viewmenu.add_command(label=players, command=LiveMenuProc(self.main, index)) self.menubar.add_cascade(label="Live Games", menu=self.viewmenu) self.helpmenu = Menu(self.menubar, tearoff=0) self.helpmenu.add_command(label="About", command=self.hello) self.menubar.add_cascade(label="Help", menu=self.helpmenu) self.root.config(menu=self.menubar, bd=3, relief=GROOVE) #the info bar self.iwpl = Label(self.info_frame, text="White Player").grid(row=0,column=0, sticky=W) self.iwp = Label(self.info_frame, textvariable=self.WhitePlayer, width=18, anchor=W) self.iwp.config(font=self.myFont) self.iwp.grid(row=0,column=1, sticky=W) self.ibpl = Label(self.info_frame, text="Black Player").grid(row=0,column=2, sticky=W) self.ibp = Label(self.info_frame, textvariable=self.BlackPlayer, width=18, anchor=W) self.ibp.config(font=self.myFont) self.ibp.grid(row=0,column=3, sticky=W) self.irsl = Label(self.info_frame, text="Result").grid(row=0,column=4, sticky=W) self.irs = Label(self.info_frame, textvariable=self.Result, width=5, anchor=W) self.irs.config(font=self.myFont) self.irs.grid(row=0,column=5, sticky=W) self.ievl = Label(self.info_frame, text="Event").grid(row=1,column=0, sticky=W) self.iev = Label(self.info_frame, textvariable=self.Event, width=18, anchor=W) self.iev.config(font=self.myFont) self.iev.grid(row=1,column=1, sticky=W) self.idtl = Label(self.info_frame, text="Date").grid(row=1,column=2, sticky=W) self.idt = Label(self.info_frame, textvariable=self.Date, width=18, anchor=W) self.idt.config(font=self.myFont) self.idt.grid(row=1,column=3, sticky=W) self.irnl = Label(self.info_frame, text="Round").grid(row=1,column=4, sticky=W) self.irn = Label(self.info_frame, textvariable=self.Round, width=5, anchor=W) self.irn.config(font=self.myFont) self.irn.grid(row=1,column=5, sticky=W) self.info_frame.grid(row=0, column=0, sticky=W) # the button bar self.bs = Button(self.buttonbar, text="setup", width=6, command=self.main.board_begin_position_clicked) self.bs.grid(sticky=W, padx=2, pady=8, row=0, column=0) self.bc = Button(self.buttonbar, text="clear", width=6, command=self.main.board_clear_clicked) self.bc.grid(sticky=W, padx=2, pady=2, row=0, column=1) self.rs = Radiobutton(self.buttonbar, text="pieces set-up", variable=self.phase, value=dc.SETUP_MODE, command=self.setup_mode) self.rs.grid(sticky=W, padx=2, pady=2, row=0, column=2) self.rp = Radiobutton(self.buttonbar, text="play", variable=self.phase, value=dc.PLAY_MODE, command=self.play_mode) self.rp.grid(sticky=W, padx=2, pady=2, row=0, column=3) self.rs.select() self.tx = Label(self.frame_right_hand, textvariable=self.status_display).grid(row=0,pady=8, padx=6) self.status_display.set("Setup Mode!") self.wc = Radiobutton(self.current_player_frame, text="", variable=self.current_white_player, value=dc.COMPUTER) self.wh = Radiobutton(self.current_player_frame, text="", variable=self.current_white_player, value=dc.HUMAN_PLAYER) self.wr = Radiobutton(self.current_player_frame, text="", variable=self.current_white_player, value=dc.REMOTE_PLAYER) self.wm = Radiobutton(self.current_player_frame, text="", variable=self.current_color_on_move, value=dc.WHITE_ON_MOVE \ ,command=self.main.ChangeColor) self.wc.grid(sticky=E, padx=6, pady=4, row=0, column=0) self.wh.grid(sticky=E, padx=6, pady=4, row=1, column=0) self.wr.grid(sticky=E, padx=6, pady=4, row=2, column=0) self.wm.grid(sticky=E, padx=6, pady=4, row=3, column=0) self.bc = Radiobutton(self.current_player_frame, text="computer", variable=self.current_black_player, value=dc.COMPUTER) self.bh = Radiobutton(self.current_player_frame, text="human player", variable=self.current_black_player, value=dc.HUMAN_PLAYER) self.br = Radiobutton(self.current_player_frame, text="remote player", variable=self.current_black_player, value=dc.REMOTE_PLAYER) self.bm = Radiobutton(self.current_player_frame, text="on move", variable=self.current_color_on_move, value=dc.BLACK_ON_MOVE \ ,command=self.main.ChangeColor) self.bc.grid(sticky=W, padx=2, pady=4, row=0, column=1) self.bh.grid(sticky=W, padx=2, pady=4, row=1, column=1) self.br.grid(sticky=W, padx=2, pady=4, row=2, column=1) self.bm.grid(sticky=W, padx=2, pady=4, row=3, column=1) self.wh.select() self.bc.select() self.wm.select() self.current_player_frame.grid(row=1) self.acb = Checkbutton(self.frame_right_hand, text="Auto Move", variable=self.auto_move).grid(sticky=W,row=2, pady=4, padx=6) self.auto_move.set(0) # set it off self.inv = Checkbutton(self.frame_right_hand, text="Invert Board", variable=self.invert_board).grid(sticky=W,row=3,pady=4, padx=6) self.invert_board.set(0) self.res = Label(self.frame_right_hand, textvariable=self.result_text).grid(row=5,pady=4, padx=6) self.result_text.set("No games") ## self.scrollbar = Scrollbar(self.depth_list_box_frame, orient=VERTICAL) ## self.depth_list_box = Listbox(self.depth_list_box_frame, selectmode=SINGLE, yscrollcommand=self.scrollbar.set, height = 1) ## self.scrollbar.config(command=self.depth_list_box.yview) ## self.scrollbar.pack(side=RIGHT, fill=Y) ## self.depth_list_box.insert(END, "depth = 2") ## self.depth_list_box.insert(END, "depth = 4") ## self.depth_list_box.insert(END, "depth = 6") ## self.depth_list_box.insert(END, "depth = 8") ## self.depth_list_box.insert(END, "depth = 10") ## self.depth_list_box.insert(END, "depth = 12") ## self.depth_list_box.insert(END, "depth = 14") ## self.depth_list_box.insert(END, "depth = 16") ## self.depth_list_box.pack(side=LEFT, fill=BOTH, expand=1) ## self.depth_list_box.select_set(3) # preset ## self.depth_list_box.see(3) self.scroll = Scrollbar (self.frame_notation_frame, orient=VERTICAL ) self.notation = Text(self.frame_notation_frame, yscrollcommand = self.scroll.set) self.scroll.command = self.notation.yview self.notation.grid(row=0, column = 0) self.scroll.grid(row=0, column = 1, sticky =N+S) self.notation.insert(END, "Welcome") self.notation.config(font = ("Courier", 9)) self.frame_left_hand.grid(column=0, row=0, sticky=N+S) self.board_frame.grid(column=1, row=0) self.frame_right_hand.grid(column=2, row=0, sticky=N) self.black_numbers = Label(self.frame_left_hand, textvariable = self.black_numbers_display) self.white_numbers = Label(self.frame_left_hand, textvariable = self.white_numbers_display) self.white_numbers.grid(row=0,column=0, sticky=N+S) self.black_numbers.grid(row=1,column=0, sticky=N+S) self.white_numbers_display.set( "0 (0)") self.black_numbers_display.set( "0 (0)") #self.menubar.grid(row=0) self.buttonbar.grid(row=1, column=0, sticky=W) self.frame_remaining_layout.grid(row=2, column=0, sticky=W+E) self.frame_notation_frame.grid(row=3, column=0, sticky=N+E+S+W) #self.frame_overall_frame.grid(sticky=N+E+S+W) return # __init__
def popUpText(self, text): self.popUpList = [] self.popUpFont = tkFont.Font(size="50") self.popUpList.append(self.create_rectangle(BORDER, HEIGHT / 2 - BORDER, WIDTH - BORDER, HEIGHT / 2 + BORDER, fill="white", width=0, tag="popUp")) self.popUpList.append(self.create_text(WIDTH / 2, HEIGHT / 2, text=text, font=self.popUpFont, tag="popUp")) self.after(1500, self.remPopUpText)
desc2 = 'Limited HID Driver: ' + limitedHidDriver + \ '\n' + 'Security Pic Index: ' + securityPicIndex + \ '\n' + 'Interfaces:' for i in interfaceList: desc2 += '\n' + i else: # Add device description for the user mode desc2 = 'Device Description: ' + description # Display the text l0 = Label(frame_desc, justify=LEFT, padx=10, text=desc0) l0.pack(anchor=W) l1 = Label(frame_desc, justify=LEFT, padx=10, text=desc1) l1.pack(anchor=W) l2 = Label(frame_desc, justify=LEFT, padx=10, text=desc2) l2.pack(anchor=W) # Underline the desc1 desc1Font = tkFont.Font(l1, l1.cget("font")) desc1Font.configure(underline=True) l1.configure(font=desc1Font) # Construct the OK/Cancel buttons Button(frame_butt, text="This is my device", command=okCallBack).pack(side='right') Button(frame_butt, text="This is NOT my device!", command=cancelCallBack).pack(side='left') # Launch the GUI mainloop()
def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold") self.configure(background='LightSteelBlue2') self.title("Battery Monitoring Tool") self.resizable(0, 0) self.focus_set() self.bind("<Escape>", lambda e: e.widget.quit()) # Vars self.monitoring_bool = False self.log_file_opened = False self.log_counter = 0 # Power Source self.power_source_label = tk.Label(self, text="Power Source :", background="LightSteelBlue2", font=tkfont.Font(family='Helvetica', size=12), anchor="e") self.power_source_label.grid(sticky="e", row=0, column=0, pady=(5, 2), padx=5) self.power_source_value = tk.Label(self, text="Battery", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12, weight=tkfont.BOLD)) self.power_source_value.grid(row=0, column=1, pady=(5, 2), padx=5) # Charging State self.charging_state_label = tk.Label(self, text="Charging State :", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12), anchor="e") self.charging_state_label.grid(sticky="e", row=0, column=2, pady=(5, 2), padx=5) self.charging_state_value = tk.Label(self, text="Charging", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12, weight=tkfont.BOLD)) self.charging_state_value.grid(row=0, column=3, pady=(5, 2), padx=5) # Main ADC Value self.main_adc_voltage_label = tk.Label( self, text="Main ADC Voltage :", background="LightSteelBlue2", font=tkfont.Font(family='Helvetica', size=12), anchor="e") self.main_adc_voltage_label.grid(sticky="e", row=1, column=0, pady=(0, 2), padx=5) self.main_adc_voltage_value = tk.Label(self, text="1000mV", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12, weight=tkfont.BOLD)) self.main_adc_voltage_value.grid(row=1, column=1, pady=(0, 2), padx=5) # Aux ADC Value self.aux_adc_voltage_label = tk.Label(self, text="Aux ADC Voltage :", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12), anchor="e") self.aux_adc_voltage_label.grid(sticky="e", row=1, column=2, pady=(0, 2), padx=5) self.aux_adc_voltage_value = tk.Label(self, text="1000mV", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12, weight=tkfont.BOLD)) self.aux_adc_voltage_value.grid(row=1, column=3, pady=(0, 2), padx=5) # Aux Charge Status self.aux_charge_status_label = tk.Label(self, text="Aux Charge Status :", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12), anchor="e") self.aux_charge_status_label.grid(sticky="e", row=2, column=0, pady=(0, 2), padx=5) self.aux_charge_status_value = tk.Label(self, text="2", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12, weight=tkfont.BOLD)) self.aux_charge_status_value.grid(row=2, column=1, pady=(0, 2), padx=5) # Aux Charge Current self.aux_charge_current_label = tk.Label(self, text="Aux Charge Current :", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12), anchor="e") self.aux_charge_current_label.grid(sticky="e", row=2, column=2, pady=(0, 2), padx=5) self.aux_charge_current_value = tk.Label(self, text="2", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12, weight=tkfont.BOLD)) self.aux_charge_current_value.grid(row=2, column=3, pady=(0, 2), padx=5) # Aux Stepdown Voltage self.aux_stepdown_voltage_label = tk.Label( self, text="Aux Stepdown Voltage :", background="LightSteelBlue2", font=tkfont.Font(family='Helvetica', size=12), anchor="e") self.aux_stepdown_voltage_label.grid(sticky="e", row=3, column=0, pady=(0, 2), padx=5) self.aux_stepdown_voltage_value = tk.Label( self, text="2", background="LightSteelBlue2", font=tkfont.Font(family='Helvetica', size=12, weight=tkfont.BOLD)) self.aux_stepdown_voltage_value.grid(row=3, column=1, pady=(0, 2), padx=5) # Aux DAC data register value self.aux_data_register_label = tk.Label(self, text="Aux DAC DATA :", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12), anchor="e") self.aux_data_register_label.grid(sticky="e", row=3, column=2, pady=(0, 2), padx=5) self.aux_data_register_value = tk.Label(self, text="2", background="LightSteelBlue2", font=tkfont.Font( family='Helvetica', size=12, weight=tkfont.BOLD)) self.aux_data_register_value.grid(row=3, column=3, pady=(0, 2), padx=5) # Action Buttons self.platform_connect_button = tk.Button( self, text="Start Charge", font=tkfont.Font(family='Helvetica', size=9), width="18", command=lambda: [self.action_button(True, False, False, False, 0, False)]) self.platform_connect_button.grid(row=4, column=0, pady=(5, 2), padx=5) self.platform_connect_button = tk.Button( self, text="Stop Charge", font=tkfont.Font(family='Helvetica', size=9), width="18", command=lambda: [self.action_button(False, True, False, False, 0, False)]) self.platform_connect_button.grid(row=4, column=1, pady=(5, 2), padx=5) self.platform_connect_button = tk.Button( self, text="Screen Power: USB", font=tkfont.Font(family='Helvetica', size=9), width="18", command=lambda: [self.action_button(False, False, True, False, 0, False)]) self.platform_connect_button.grid(row=4, column=2, pady=(5, 2), padx=5) self.platform_connect_button = tk.Button( self, text="Screen Power: Battery", font=tkfont.Font(family='Helvetica', size=9), width="18", command=lambda: [self.action_button(False, False, False, True, 0, False)]) self.platform_connect_button.grid(row=4, column=3, pady=(5, 2), padx=5) # Log output self.log_output_text = tk.Text(self, width=80, height=8, wrap=tk.WORD) self.log_output_text.grid(row=5, column=0, columnspan=4, pady=(15, 2), padx=20) # Monitor Button self.empty_label = tk.Label(self, text="", background="LightSteelBlue2", font=tkfont.Font(family='Helvetica', size=12), anchor="e") self.empty_label.grid(sticky="e", row=6, column=0, pady=(5, 2), padx=5) self.monitor_button = tk.Button( self, text="Start Battery Monitoring", font=tkfont.Font(family='Helvetica', size=9), width="40", command=lambda: [self.monitor_button_action()]) self.monitor_button.grid(row=6, column=1, columnspan=2, pady=(5, 2), padx=5) # Force Charge Voltage Row self.force_charge_voltage_label = tk.Label( self, text="Force Charge Voltage :", background="LightSteelBlue2", font=tkfont.Font(family='Helvetica', size=12), anchor="e") self.force_charge_voltage_label.grid(sticky="e", row=7, column=0, pady=(25, 15), padx=5) self.frame_mv = tk.Frame(self, background="LightSteelBlue2") self.force_charge_voltage_text_var = tk.IntVar() self.force_charge_voltage_text = tk.Entry( self.frame_mv, width=10, justify='center', textvariable=self.force_charge_voltage_text_var) self.force_charge_voltage_text.pack(side=tk.LEFT, pady=(0, 0), padx=(0, 0)) self.force_charge_voltage_label_mv = tk.Label( self.frame_mv, text=" mV", background="LightSteelBlue2", font=tkfont.Font(family='Helvetica', size=12)) self.force_charge_voltage_label_mv.pack(side=tk.LEFT, pady=(0, 0), padx=(0, 0)) self.frame_mv.grid(row=7, column=1, pady=(25, 15), padx=5) self.platform_connect_button = tk.Button( self, text="Force Charge Voltage", font=tkfont.Font(family='Helvetica', size=9), width="18", command=lambda: [ self.action_button(False, False, False, False, self.force_charge_voltage_text_var.get(), False) ]) self.platform_connect_button.grid(row=7, column=2, pady=(25, 15), padx=5) self.platform_connect_button = tk.Button( self, text="Stop Force Charge", font=tkfont.Font(family='Helvetica', size=9), width="18", command=lambda: [self.action_button(False, False, False, False, 0, True)]) self.platform_connect_button.grid(row=7, column=3, pady=(25, 15), padx=5) # Device connection self.mooltipass_device = mooltipass_hid_device() # Connect to device if self.mooltipass_device.connect(True) == False: sys.exit(0) # Debug self.log_output_text.insert("end", "Connected to device\r\n") self.log_output_text.see(tk.END) # Force UI update self.update_idletasks() self.update() # Initial value fetch self.after(500, self.action_button(False, False, False, False, 0, False))
def __init__(self,master): top=self.top=Toplevel(master) self.l=Label(top,text='Secure your syringe/lysate maker in place',font=tkFont.Font(family='Helvetica', size=24),padx=4,pady=4) self.l.pack() self.b=Button(top,text='Ready to Lyse!',height=4,width=12,padx=4,pady=4,font=tkFont.Font(family='Helvetica', size=12),command=self.cleanup) self.b.pack()
#3) helpMenu = Menu(menubar, tearoff=0) aboutMenu.add_command(label="how to use this app") menubar.add_cascade(label="help", menu=helpMenu) # Button to gray scale. scaler_button = Button(master=root, text="Convert to gray", bg="#2672EC", fg="#ffffff", activebackground="#19c90e", activeforeground="#FFFFFF", overrelief=GROOVE, cursor="hand2", font=tkFont.Font(size=11), relief=FLAT, command=converter) scaler_button.place(x=30, y=530) #Text View that shows the path of the new gray image path_to_gray = "Path of the output image" path_finder = Label(master=root, text=path_to_gray) path_finder.place(x=200, y=530) # to display the menu root.config(menu=menubar) #btn_file_opener.pack(side=TOP, expand=True) root.configure(background="#000")
def __init__(self,master): top=self.top=Toplevel(master) self.l=Label(top,text='Remove syringe for motors to move to set volume',font=tkFont.Font(family='Helvetica', size=24),padx=4,pady=4) self.l.pack() self.b=Button(top,text='Move Motors!',height=4,width=12,padx=4,pady=4,font=tkFont.Font(family='Helvetica', size=12),command=self.cleanup) self.b.pack()
sys.exit(0) def makenew(): # if we get to here let's destroy the window and just move on from_config.destroy() if __name__ == '__main__': ############### From Config ########################## from_config = Tk.Tk() from_config.wm_title("SMIA-CUKIE") customFont = tkFont.Font(root=from_config, family="Helvetica", size=80) title_label = Tk.Label(from_config, text="SMIA-CUKIE", font=customFont, fg='blue') title_explain = Tk.Label( from_config, text= "Simultaneous Multi-Channel Immunofluorescence Analysis\n By Gil Cukierman", fg='blue') instructions_label = Tk.Label( justify=Tk.LEFT, anchor=Tk.W,
def create_tooltip(self, item_id, **kwargs): assert (type(item_id) is int), "Invalid item id!" obj = self._contents[self._contents.index(item_id)] if obj.instance == None: return # restricting tooltips to TimeMarker and SequenceItem if not(isinstance(obj.instance,TimeMarker) or\ isinstance(obj.instance,SequenceItem)): return # pull kw input for anchor if 'anchor' in kwargs: text_anchor = kwargs.pop('anchor') else: if isinstance(obj.instance, TimeMarker): text_anchor = text_anchor = 'nauto' elif isinstance(obj.instance, SequenceItem): text_anchor = text_anchor = 'auto' # deal with anchoring assert (type(text_anchor) is str \ and text_anchor.lower() in (tk.N,tk.NE,tk.E,tk.SE,tk.S,\ tk.SW,tk.W,tk.NW,tk.CENTER,\ 'auto','nauto','sauto')),\ "Invalid vertical position!" # 'automatic' positioning if text_anchor.lower() in ('auto', 'nauto', 'sauto'): text_anchor = { 'auto': '', 'nauto': 'n', 'sauto': 's' }[text_anchor.lower()] if self.x_pixel(obj.instance.s) > self.size[1] / 2: text_anchor += tk.E else: text_anchor += tk.W # vertical position if text_anchor.lower() == tk.CENTER: text_anchor = '' if tk.S.lower() in text_anchor: ypos = self.size[0] - 2 elif tk.N.lower() in text_anchor: ypos = 3 else: ypos = self.size[0] / 2 - 2 text_anchor = text_anchor.lower() # horizontal positioning & color if isinstance(obj.instance, TimeMarker): xpos = self.x_pixel(obj.instance.s) if self._is_start_marker(obj.instance): textcolor = CHANNELFRAME_START_MARKER_COLOR elif self._is_end_marker(obj.instance): textcolor = CHANNELFRAME_END_MARKER_COLOR else: textcolor = CHANNELFRAME_MARKER_COLOR elif isinstance(obj.instance, SequenceItem): textcolor = CHANNELCANVAS_NOSEL_COLOR if obj.instance.item_type in ('pulse', 'ramp'): xpos = self.x_pixel(obj.instance.s + obj.instance.s / 2.0) text_anchor = text_anchor.replace(tk.E.lower(), '').replace( tk.W.lower(), '') elif obj.instance.item_type == 'set': xpos = self.x_pixel(obj.instance.s) if text_anchor == '': text_anchor = tk.CENTER # place tooltip item_id = self.create_text(xpos,ypos,text=" "+str(obj)+" ",\ anchor=text_anchor,\ fill=textcolor,\ font=tkFont.Font(size=self.ttfontsize),\ tags=('tooltip','dynamic')) return item_id
toolTip = ToolTip(widget) def enter(event): toolTip.showtip(text) def leave(event): toolTip.hidetip() widget.bind('<Enter>', enter) widget.bind('<Leave>', leave) # Main windows root = Tk() # create a Tk root window root.wm_title("Neural Network Toolbox") # Window variables w = 1024 # width for the Tk root h = 730 # height for the Tk root tkFont.Font(family="Times", size=10, weight=tkFont.BOLD) ws = root.winfo_screenwidth() # width of the screen hs = root.winfo_screenheight() # height of the screen x = (ws/2) - (w/2) y = (hs/2) - (h/2) root.geometry('%dx%d+%d+%d' % (w, h, x, y)) # set the dimensions of the screen and where it is placed def debug(o): print "debug: "+o def about(): print "HELP" ##################
def __init__(self, parent, canvas_function, features): #Se crea el Frame Padre sobre el que descansará toda la infraestructura #gráfica. tk.Frame.__init__(self, parent, relief="groove") #En esta sección se brindarán algunos vínculos para poder saltar a la #información pertinente más rápidamente sin necesidad de pasar por todas #las secciones; para ello es necesario capturar la función que se pasa como #parámetro que permite moverse de una región a otra basándose en un par de #coordenadas. self.__canvas_function = canvas_function #Se obtiene el color de fondo del Frame principal. self.__parent_bg = features["parent_bg"] #A continuación se crean dos subframes, uno contendrá las imágenes de los #escudos de la U.N.A.M y la Facultad de Ciencias mientras que el otro tendrá #la introducción al tema. self.__image_frame = tk.Frame(self) self.__text_frame = tk.Frame(self) #A continuación se crean las tipografías que serán empleadas para mostrar #la información pertinente. self.__title_font = tkf.Font(family="Helvetica", size=19, weight="bold") self.__name_font = tkf.Font(family="Helvetica", size=10, weight="bold") self.__value_font = tkf.Font(family="Helvetica", size=12) #Esta Frame usará íconos, en específico los escudos de la U.N.A.M. y #la Facultad de Ciencias, entonces se cargan automáticamente todas #las imágenes disponibles y aquí se decide cuál usar (véase View/Image y View/MainWindow.py) self.__images = features["images"] #Se obtiene el ícono del escudo de la U.N.A.M. self.__unam_shield_image = self.__images["unam_shield"] self.__unam_shield_label = tk.Label(self.__image_frame, image=self.__unam_shield_image) #Se obtiene el ícono del escudo de la Facultad de Ciencias. self.__sciences_shield_image = self.__images["sciences_shield"] self.__sciences_shield_label = tk.Label( self.__image_frame, image=self.__sciences_shield_image) #Se crea el Label del mensaje de bienvenida al usuario y se le da el #formato apropiado. self.__welcome_label = tk.Label(self.__image_frame, text="Welcome to M.O.E.A. Software") self.__welcome_label["font"] = self.__title_font #Se colocan los Labels a manera de grid (malla). self.__unam_shield_label.grid(row=0, column=0, padx=(1, 260), pady=(8, 10), sticky=tk.W) self.__sciences_shield_label.grid(row=0, column=1, pady=(8, 10), sticky=tk.E) self.__welcome_label.grid(row=1, column=0, columnspan=2, pady=(1, 10), sticky=tk.N + tk.S) #Ahora se crean los Labels con el título para identificar la información de cada una de #las secciones gráficas creadas en el proyecto. self.__decision_variables_title_label = tk.Label( self.__text_frame, text="Decision Variables") self.__objective_functions_title_label = tk.Label( self.__text_frame, text="Objective Functions") self.__population_settings_title_label = tk.Label( self.__text_frame, text="Population Settings") self.__genetic_operators_settings_title_label = tk.Label( self.__text_frame, text="Genetic Operators Settings") self.__moeas_settings_title_label = tk.Label(self.__text_frame, text="MOEAs Settings") #A las Labels antes mencionadas se les da el formato apropiado. self.__decision_variables_title_label["font"] = self.__title_font self.__objective_functions_title_label["font"] = self.__title_font self.__population_settings_title_label["font"] = self.__title_font self.__genetic_operators_settings_title_label[ "font"] = self.__title_font self.__moeas_settings_title_label["font"] = self.__title_font #Se crean los elementos gráficos conocidos como Text, los cuales almacenarán #la información correspondiente a la sección que representan. self.__introduction_text = tk.Text(self.__text_frame, height=28, width=62, background=self.__parent_bg, relief="flat") self.__decision_variables_text = tk.Text(self.__text_frame, height=26, width=62, background=self.__parent_bg, relief="flat") self.__objective_functions_text = tk.Text(self.__text_frame, height=35, width=62, background=self.__parent_bg, relief="flat") self.__population_settings_text = tk.Text(self.__text_frame, height=26, width=62, background=self.__parent_bg, relief="flat") self.__genetic_operators_settings_text = tk.Text( self.__text_frame, height=27, width=62, background=self.__parent_bg, relief="flat") self.__moeas_settings_text = tk.Text(self.__text_frame, height=25, width=62, background=self.__parent_bg, relief="flat") #A cada uno de los Text se le da el formato apropiado para ser mostrado en la pantalla. self.__introduction_text["font"] = self.__value_font self.__decision_variables_text["font"] = self.__value_font self.__objective_functions_text["font"] = self.__value_font self.__population_settings_text["font"] = self.__value_font self.__genetic_operators_settings_text["font"] = self.__value_font self.__moeas_settings_text["font"] = self.__value_font #Las siguientes son coordenadas (en Y) que se usarán para redirigir al usuario #hacia posiciones específicas. self.__destination_coordinates = { '0': 0.20176767676767676, '1': 0.3522727272727273, '2': 0.5484848484848485, '3': 0.6989898989898989, '4': 1 } #Aquí irán los nombres de las ligas que redireccionarán al usuario hacia #posiciones específicas del Frame. link_quotes = [ """ Decision Variables\n""", """ Objective Functions\n""", """ Population Settings\n""", """ Genetic Operators Settings\n""", """ MOEAs Settings\n""" ] #A continuación se muestran las líneas que conformarán la introducción. introduction_quotes = [ """The following software product solves Multi-Objective problems using evolutionary algorithms as a basis and altogether with the software documentation and the written work they define the project that the citizen Aarón Martín Castillo Medina presents in order to obtain his Bachelor Science degree in Computer Science.\n""", """\n""", """The main goal is to facilitate the comprehension of M.O.E.A.'s (Multi-Objective Evolutionary Algorithms) through a simple, dynamic and modifiable program in order to divulge these kind of techniques and therefore, inviting those people interested (if possible) to considerate and acquire these topics in their academic or working activities.\n""", """\n""", """Each one of the sections of this program will be briefly described, whereby it is highly recommended to check both the software documentation and the written work in case of a misunderstanding, because they serve as a complement trying to not repeating the same information in the whole project.\n""", """The created sections are listed below (if you want to skip to a specific one just click on it; if you want to return to the beginning click on the button "Restore Settings"):\n""", """\n""" ] #Ahora se implementan las línas que conformarán la sección Decision Variables #(ó Variables de Decisión). decision_variables_quotes = [ """According to the Multi-Objective environment, a decision variable means at first sight the restriction binded to the objective functions in order to get the optimal solution, it is important to mention that if there are two or more decision variables it is called a Multi-Criteria problem, therefore the user must not confuse both the Multi-Objective and the Multi-Criteria terms because they are independent from each other.\n""", """\n""", """At second sight the best values for every decision variable (considering their restrictions) will shape the optimal solution, this means that the optimal solution will be the best choice for each one of the objective functions inserted by the user, there can be more than one optimal solution. The set of optimal solutions is called the Pareto Optimal.\n""", """\n""", """In the respective section there is already implemented the necessary infrastructure so the user can add as many decision variables as desired. All of them must have an identifier (name) and both the lower and upper ranges (restrictions).\n""", """\n""", """Finally at the menu "Edit -> Options" there is a feature called "M.O.P. Examples". It is basically a set of benchmarks (each one is a mixture of objective functions and decision variables) whose behavior is already studied. These M.O.P.s can be loaded into both the Decision Variables and the Objective Functions sections so the user can get an easy way of testing and learning from the software product.\n""" ] #Luego se implementan las líneas que construirán la sección Objective Functions (ó #Funciones Objetivo). objective_functions_quotes = [ """Continuing with the Multi-Objective development, the objective functions are precisely the "goals" used to get the optimal solution.\nUsually the perspective is to obtain the desired solution which minimizes all the functions, but in case when the user needs to get the ideal solution which maximizes at least one of them (functions), the software product has already considered this case, this means that a special feature has been created in the section to allow the user the selection of either maximizing or minimizing one single function.\nBy the way, the set of optimal solutions evaluated in the objective functions is called the Pareto Front.\n""", """\n""", """Moreover, the respective section is developed so the user can insert as much objective functions as desired, however, they must be inserted using Python syntax.\nFor basic purposes it only means that the operator ^ (exponential) changes to ** and when a fraction appears, at least one of the factors must include a decimal point even if the result is integer (example: 4/2 -> 4.0/2.0); the other operators remain the same.\nNevertheless, when the user tries to insert advanced operators such as trigonometric functions, there is a special menu at "Edit -> Options" called "Python Expressions"; this contains nothing but renamed functions (officially called syntactic sugar) so the Python interpreter can "understand" them.\nWith this feature the user will be able to add as many advanced operators as possible. There are some preloaded examples to understand better these options.\n""", """\n""", """Finally at the same menu "Edit -> Options" there is another feature called "M.O.P. Examples". It is basically a set of benchmarks (each one is a mixture of objective functions and decision variables) whose behavior is already studied. These M.O.P.s can be loaded into both the Decision Variables and the Objective Functions sections so the user can get an easy way of testing and learning from the software product.\n""" ] #Ahora se construyen las líneas que darán forma a la #sección Population Settings (ó Características de la Población). population_settings_quotes = [ """This section starts with the evolutionary environment related to the Multi-Objective development.\nIn order to get the optimal solution, the computer suggests initial random solutions so they can "evolve" into more adaptable ones, that is, upgrading the solutions using techniques based on natural selection theories in order to obtain those that minimize the most the objective functions provided by the user.\nThe set of the suggested solutions and their eventual upgrades is called a Population, and each one of them (for the project's purposes) is called an Individual.\n""", """\n""" """By using this section the user will define the Population's characteristics such as the chromosomal representation which leads into the mathematical representation to upgrade one solution, the number of Individuals, the number of decimals in each solution (see the Decision Variables section), the number of generations (iterations) needed to upgrade the Population and the selection of Fitness.\nFitness is basically a measure which indicates the level of superiority of an Individual, usually the amount of Fitness is proportional to that superiority, this factor is essential when the evolving operations are being executed.\n""", """\n""", """It is important to mention that the chromosomal representation selected must coincide with both Crossover and Mutation operators used at "Genetic Operators Settings".\n""" ] #Luego se crean las líneas que formarán parte de la sección #Genetic Operators Settings (ó Características de los Operadores Genéticos). genetic_operators_settings_quotes = [ """When a Population is about being upgraded, actually it means that a new Population is created based on the "old one", such operation is called the generation of an offspring.\nJust like in the biological ecosystems, this method allows to obtain more adaptable Individuals by selecting and combining their genetic payload (provided in this case by the chromosomal representation).\n""", """\n""", """In this section there are three operators involved in the generation of an offspring:\n *The Selection operator which, based on the Fitness, selects the optimal Individuals in order to define the new Population.\n *The Crossover operator, which consists on a sexual reproduction in order to create new Individuals.\n *The Mutation operator which changes the genetic payload in the recently created Individuals so the Population do not stay stuck in the same genetic features.\n""" """\n""", """There are many implementations for each one of these operators but generally speaking, all of them are considered in this section, therefore the user can select and modify the techniques or values regarding this evolutionary process.\n""", """\n""", """It is important to mention that the techniques related to both Crossover and Mutation operators must coincide with the chromosomal representation selected at "Population Settings.\n""" ] #Finalmente se crean las líneas que constituirán la sección #MOEAS Settings (ó Características de los MOEAs). moeas_settings_quotes = [ """In this section the user can choose one technique (M.O.E.A) from a concise variety of M.O.E.A.s.\nThe M.O.E.A. provides the set of optimal solutions according to the objective functions given; to reach this goal the M.O.E.A. uses all the information gathered in this and the other sections as well.\nThe main difference between one M.O.E.A and another is the applied restriction (also called selective pressure) when it is choosing the optimal Individuals.\nThis project contains the most representative algorithms so the user can test them and see the results.\nThis sections also contains a feature called Sharing Function, it is used when the algorithm tries to make an even more restrictive selection of Individuals.\nNot all M.O.E.A.s use this option but it was considered to put this feature because of its importance in the evolutionary process.\n""", """\n""", """As usual, the user has options to his disposal in order to modify the correspondent values related to the selection of M.O.E.A. and the Sharing Function as well.\n""", """\n""", """Speaking of which, the configurations established in this program are related to the use of the NSGA-II algorithm, that is because in all the scientific sources the authors consider this algorithm as a benchmark, so the same is done here.""" ] #A continuación se coloca la información correspondiente a la introducción #en su Text correspondiente. for quote in introduction_quotes: self.__introduction_text.insert(tk.END, quote) #Para poder acceder a la información más rápidamente, se colocan ligas (links) para cada #una de las secciones gráficas. Cuando el usuario dé click en alguna de éstas será redireccionado #al inicio de la información de la sección en cuestión. for x in range(len(link_quotes)): current_quote = link_quotes[x] self.__introduction_text.insert(tk.END, current_quote, ("link", str(x))) #Las ligas se colocan de color azul. self.__introduction_text.tag_config("link", foreground="blue") #Se agrega el evento de cada una de las ligas. self.__introduction_text.tag_bind("link", "<Button-1>", self.__go_to_selected_section) #Ahora se coloca la información relativa a las variables de decisión (Decision Variables). for quote in decision_variables_quotes: self.__decision_variables_text.insert(tk.END, quote) #A continuación la información relativa a las funciones objetivo (Objective Functions) #es colocada. for quote in objective_functions_quotes: self.__objective_functions_text.insert(tk.END, quote) #Luego la información relacionada con las características de la Población (Population Settings) #es mostrada. for quote in population_settings_quotes: self.__population_settings_text.insert(tk.END, quote) #La información concerniente a las características para la descendencia de una Población #(Genetic Operators Settings) es mostrada. for quote in genetic_operators_settings_quotes: self.__genetic_operators_settings_text.insert(tk.END, quote) #Ahora la información aunada a las características para el uso de MOEAs y Sharing Functions ó #Funciones de Compartición (MOEAs Settings) es colocada. for quote in moeas_settings_quotes: self.__moeas_settings_text.insert(tk.END, quote) #Dado que la introducción será colocada en Text, éstos por defecto pueden #modificar su contenido, por ello es que una vez que se les insertó la información, #se desactivan para no permitir que el usuario cambie la información. self.__introduction_text.configure(state=tk.DISABLED) self.__decision_variables_text.configure(state=tk.DISABLED) self.__objective_functions_text.configure(state=tk.DISABLED) self.__population_settings_text.configure(state=tk.DISABLED) self.__genetic_operators_settings_text.configure(state=tk.DISABLED) self.__moeas_settings_text.configure(state=tk.DISABLED) #A continuación se colocan los Text que identifican a cada sección del texto #y los Text que indican la información de cada sección. Esto sucede en el Text Frame. El método #de colocación es en forma de malla (grid). self.__introduction_text.grid(row=0, column=0, padx=(1, 1), pady=(1, 1), sticky=tk.W) self.__decision_variables_title_label.grid(row=1, column=0, padx=(1, 1), pady=(1, 7), sticky=tk.N + tk.S) self.__decision_variables_text.grid(row=2, column=0, padx=(1, 1), pady=(1, 1), sticky=tk.W) self.__objective_functions_title_label.grid(row=3, column=0, padx=(1, 1), pady=(1, 7), sticky=tk.N + tk.S) self.__objective_functions_text.grid(row=4, column=0, padx=(1, 1), pady=(1, 1), sticky=tk.W) self.__population_settings_title_label.grid(row=5, column=0, padx=(1, 1), pady=(1, 7), sticky=tk.N + tk.S) self.__population_settings_text.grid(row=6, column=0, padx=(1, 1), pady=(1, 1), sticky=tk.W) self.__genetic_operators_settings_title_label.grid(row=7, column=0, padx=(1, 1), pady=(1, 7), sticky=tk.N + tk.S) self.__genetic_operators_settings_text.grid(row=8, column=0, padx=(1, 1), pady=(1, 1), sticky=tk.W) self.__moeas_settings_title_label.grid(row=9, column=0, padx=(1, 1), pady=(1, 7), sticky=tk.N + tk.S) self.__moeas_settings_text.grid(row=10, column=0, padx=(1, 1), pady=(1, 1), sticky=tk.W) #Finalmente se colocan los Subframes en el Frame principal. self.__image_frame.pack() self.__text_frame.pack()
import Tkinter import tkFont def func1(val): label1.config(text="Scale value = %d" % int(val)) top = Tkinter.Tk() sel1 = Tkinter.IntVar() sel1.set(25) string1 = "value=%d" myFont = tkFont.Font(family="Arial", size=24) label1 = Tkinter.Label(top, text="Your choice", font=myFont) label1.pack() scale1 = Tkinter.Scale(top, font=myFont, variable=sel1, orient='h', from_=0, to=100, command=func1, showvalue=False) scale1.pack(fill=Tkinter.BOTH, expand=1) top.maxsize(300, 80) top.minsize(300, 80) top.mainloop()
def __init__(self, walk): self.walk = walk self.top = Toplevel() self.top.geometry('400x1100') self.top.title("Hash View") #self.top.option_add("*Font", "TSCu_Paranar 10") self.top.option_add("*Font", "Helvetica 10") self.myBoldFont = tkFont.Font(family="helvetica", weight="bold", size=10) self.myFont = tkFont.Font(family="helvetica", size=10) # key bindings self.top.bind("<Escape>", self.esc_proc) self.top.protocol("WM_DELETE_WINDOW", self.end_proc) # the string variables for the onfo bar self.LowerBound = StringVar() self.UpperBound = StringVar() self.Node = StringVar() self.Color = StringVar() self.IsEvaluated = StringVar() self.Useless = StringVar() self.ExactValue = StringVar() self.CyclePossible = StringVar() self.JustPromoted = StringVar() self.IsExtended = StringVar() self.HasExtCondition = StringVar() self.SearchDepth = StringVar() self.DistanceFromRoot = StringVar() self.BestMoveIndex = StringVar() self.IsQuiescence = StringVar() self.HasToCapture = StringVar() self.MoveStatus = StringVar() self.Depth = StringVar() # frames self.overall_frame = Frame(self.top, relief=GROOVE, bd=4) self.info_frame = Frame(self.overall_frame, relief=RIDGE, bd=3) self.board3_frame = Frame(self.overall_frame) self.eval3_am_frame = Frame(self.overall_frame, relief=RIDGE, bd=3) self.eval3_bt_frame = Frame(self.overall_frame, relief=RIDGE, bd=3) #the info frame self.ilbl = Label(self.info_frame, text="LowerBound").grid(row=0, column=0, sticky=E) self.ilb = Label(self.info_frame, textvariable=self.LowerBound, width=6, anchor=W) self.ilb.config(font=self.myFont) self.ilb.grid(row=0, column=1, sticky=E) self.iubl = Label(self.info_frame, text="Uppder Bound").grid(row=1, column=0, sticky=E) self.iub = Label(self.info_frame, textvariable=self.UpperBound, width=6, anchor=W) self.iub.config(font=self.myFont) self.iub.grid(row=1, column=1, sticky=E) self.irsl = Label(self.info_frame, text="Node").grid(row=2, column=0, sticky=E) self.irs = Label(self.info_frame, textvariable=self.Node, width=6, anchor=W) self.irs.config(font=self.myFont) self.irs.grid(row=2, column=1, sticky=E) self.ievl = Label(self.info_frame, text="Color").grid(row=3, column=0, sticky=E) self.iev = Label(self.info_frame, textvariable=self.Color, width=6, anchor=W) self.iev.config(font=self.myFont) self.iev.grid(row=3, column=1, sticky=E) self.iewl = Label(self.info_frame, text="Search Depth").grid(row=4, column=0, sticky=E) self.iew = Label(self.info_frame, textvariable=self.SearchDepth, width=6, anchor=W) self.iew.config(font=self.myFont) self.iew.grid(row=4, column=1, sticky=E) self.iezl = Label(self.info_frame, text="Distance").grid(row=5, column=0, sticky=E) self.iez = Label(self.info_frame, textvariable=self.DistanceFromRoot, width=6, anchor=W) self.iez.config(font=self.myFont) self.iez.grid(row=5, column=1, sticky=E) self.iexl = Label(self.info_frame, text="Best Move").grid(row=6, column=0, sticky=E) self.iex = Label(self.info_frame, textvariable=self.BestMoveIndex, width=6, anchor=W) self.iex.config(font=self.myFont) self.iex.grid(row=6, column=1, sticky=E) self.ieyl = Label(self.info_frame, text="Depth").grid(row=7, column=0, sticky=E) self.iey = Label(self.info_frame, textvariable=self.Depth, width=6, anchor=W) self.iey.config(font=self.myFont) self.iey.grid(row=7, column=1, sticky=E) self.idt = Label(self.info_frame, textvariable=self.IsEvaluated, width=20, anchor=W) self.idt.config(font=self.myFont) self.idt.grid(row=0, column=3, sticky=E) self.irn = Label(self.info_frame, textvariable=self.Useless, width=20, anchor=W) self.irn.config(font=self.myFont) self.irn.grid(row=1, column=3, sticky=E) self.irm = Label(self.info_frame, textvariable=self.ExactValue, width=20, anchor=W) self.irm.config(font=self.myFont) self.irm.grid(row=2, column=3, sticky=E) self.irp = Label(self.info_frame, textvariable=self.CyclePossible, width=20, anchor=W) self.irp.config(font=self.myFont) self.irp.grid(row=3, column=3, sticky=E) self.irq = Label(self.info_frame, textvariable=self.JustPromoted, width=20, anchor=W) self.irq.config(font=self.myFont) self.irq.grid(row=4, column=3, sticky=E) self.irr = Label(self.info_frame, textvariable=self.IsExtended, width=20, anchor=W) self.irr.config(font=self.myFont) self.irr.grid(row=5, column=3, sticky=E) self.irs = Label(self.info_frame, textvariable=self.HasExtCondition, width=20, anchor=W) self.irs.config(font=self.myFont) self.irs.grid(row=6, column=3, sticky=E) self.irt = Label(self.info_frame, textvariable=self.IsQuiescence, width=20, anchor=W) self.irt.config(font=self.myFont) self.irt.grid(row=7, column=3, sticky=E) self.iru = Label(self.info_frame, textvariable=self.HasToCapture, width=20, anchor=W) self.iru.config(font=self.myFont) self.iru.grid(row=8, column=3, sticky=E) self.irw = Label(self.info_frame, textvariable=self.MoveStatus, width=20, anchor=W) self.irw.config(font=self.myFont) self.irw.grid(row=9, column=3, sticky=E) self.board3 = DraughtBoardView(self.board3_frame) self.scrollbar = Scrollbar(self.eval3_am_frame, orient=VERTICAL) self.all_moves = Listbox(self.eval3_am_frame, selectmode=SINGLE, yscrollcommand=self.scrollbar.set, height = 20, width=34,\ font = ("Courier",12)) self.scrollbar.config(command=self.all_moves.yview) self.scrollbar.pack(side=RIGHT, fill=Y) self.all_moves.insert(END, "please wait, collecting moves") self.all_moves.pack(side=LEFT, fill=BOTH, expand=1) self.show1 = Button(self.eval3_bt_frame, text="Home", command=self.walk.show_home_node_pressed) self.show2 = Button(self.eval3_bt_frame, text="Prev", command=self.walk.show_prev_node_pressed) self.show3 = Button(self.eval3_bt_frame, text="Next", command=self.walk.show_next_node_pressed) self.show4 = Button(self.eval3_bt_frame, text="Eval", command=self.walk.show_eval_node_pressed) self.show1.grid(row=0, column=0) self.show2.grid(row=0, column=1) self.show3.grid(row=0, column=2) self.show4.grid(row=0, column=3) self.info_frame.grid(row=0, column=0, sticky=W) self.board3_frame.grid(row=1, column=0) self.eval3_am_frame.grid(row=2, column=0) self.eval3_bt_frame.grid(row=3, column=0) self.overall_frame.grid() return # __init__
def __init__(self, canvas): self.win = Tk() self.canvas = canvas #variable options for the program self.type = IntVar() #custom variables self.ground = IntVar() self.flower_tree_num = IntVar() self.basic_tree_num = IntVar() self.pine_num = IntVar() self.colors = [(0, 0, 0) for i in range(COLOR_NUM)] self.button_colors = [0 for i in range(COLOR_NUM)] #titles title_font = tkFont.Font(size=22) label_font = tkFont.Font(size=16) text_font = tkFont.Font(size=14) Label(self.win, text="Options", font=title_font).grid(row=0, column=0, columnspan=12) #overall design options Label(self.win, text="Landscape type", font=label_font).grid(row=1, column=0, columnspan=12) Radiobutton(self.win, width=16, height=2, variable=self.type, font=text_font, indicatoron=0, text="Black and White", value=3, command=self.custom_callback).grid(row=2, column=0, columnspan=6) Radiobutton(self.win, width=16, height=2, variable=self.type, font=text_font, indicatoron=0, text="Custom", value=4, command=self.custom_callback).grid(row=2, column=6, columnspan=6) #ground options Label(self.win, text="Land", font=label_font).grid(row=3, column=0, columnspan=12) Label(self.win, text="Ground?", font=text_font).grid(row=4, column=5) Checkbutton(self.win, variable=self.ground).grid(row=4, column=6) Label(self.win, text="Color", font=text_font).grid(row=5, column=5) self.button_colors[0] = Button(self.win, command=lambda: self.getcolor(0), state=DISABLED) self.button_colors[0].grid(row=5, column=6) #tree options Label(self.win, text="Trees", font=label_font).grid(row=6, column=0, columnspan=8) Label(self.win, text="Branched", font=text_font).grid(row=7, column=0, columnspan=4) basic_img = ImageTk.PhotoImage(Image.open("basic-tree.png")) basicl = Label(self.win, image=basic_img) basicl.image = basic_img basicl.grid(row=8, column=0, rowspan=2, columnspan=4) self.button_colors[1] = Button(self.win, command=lambda: self.getcolor(1), state=DISABLED) self.button_colors[1].grid(row=10, column=0, columnspan=4) Scale(self.win, variable=self.basic_tree_num, orient=HORIZONTAL, from_=0, to=10).grid(row=11, column=0, columnspan=4) Label(self.win, text="Flowering", font=text_font).grid(row=7, column=4, columnspan=4) flower_img = ImageTk.PhotoImage(Image.open("flower-tree.png")) flowerl = Label(self.win, image=flower_img) flowerl.image = flower_img flowerl.grid(row=8, column=4, rowspan=2, columnspan=4) self.button_colors[2] = Button(self.win, command=lambda: self.getcolor(2), state=DISABLED) self.button_colors[2].grid(row=10, column=4, columnspan=2) self.button_colors[3] = Button(self.win, command=lambda: self.getcolor(3), state=DISABLED) self.button_colors[3].grid(row=10, column=6, columnspan=2) Scale(self.win, variable=self.flower_tree_num, orient=HORIZONTAL, from_=0, to=11).grid(row=11, column=4, columnspan=4) Label(self.win, text="Pine", font=text_font).grid(row=7, column=8, columnspan=4) pine_img = ImageTk.PhotoImage(Image.open("pine.png")) pinel = Label(self.win, image=pine_img) pinel.image = pine_img pinel.grid(row=8, column=8, rowspan=2, columnspan=4) self.button_colors[4] = Button(self.win, command=lambda: self.getcolor(4), state=DISABLED) self.button_colors[4].grid(row=10, column=8, columnspan=2) self.button_colors[5] = Button(self.win, command=lambda: self.getcolor(5), state=DISABLED) self.button_colors[5].grid(row=10, column=10, columnspan=2) Scale(self.win, variable=self.pine_num, orient=HORIZONTAL, from_=0, to=11).grid(row=11, column=8, columnspan=4) #submit button Button(self.win, text="ENTER", font=label_font, height=2, width=15, command=self.submit_callback).grid(row=20, column=0, columnspan=12)
def __init__(self, CodeClass): # Configure FoxDot's namespace to include the editor CodeClass.namespace['FoxDot'] = self CodeClass.namespace['Player'].widget = self #CodeClass.namespace['Ghost'].widget = self # Used for docstring prompt self.namespace = CodeClass.namespace # Set up master widget self.root = Tk(className='FoxDot') self.root.title("FoxDot - Live Coding with Python and SuperCollider") self.root.rowconfigure(0, weight=1) # Text box self.root.rowconfigure(1, weight=0) # Separator self.root.rowconfigure(2, weight=0) # Console self.root.grid_columnconfigure(0, weight=0) # line numbers self.root.grid_columnconfigure(1, weight=1) # Text boxes self.root.protocol("WM_DELETE_WINDOW", self.kill) # --- Set icon try: # Use .ico file by default self.root.iconbitmap(FOXDOT_ICON) except: # Use .gif if necessary self.root.tk.call('wm', 'iconphoto', self.root._w, PhotoImage(file=FOXDOT_ICON)) # --- Setup font if self.default_font not in tkFont.families(): if SYSTEM == WINDOWS: self.default_font = "Consolas" elif SYSTEM == MAC_OS: self.default_font = "Monaco" else: self.default_font = "Courier New" self.font = tkFont.Font(font=(self.default_font, 12), name="CodeFont") self.font.configure(family=self.default_font) # --- start create menu self.menu = MenuBar(self, visible=True) # Create y-axis scrollbar self.y_scroll = Scrollbar(self.root) self.y_scroll.grid(row=0, column=2, sticky='nsew') # Create text box for code self.text = ThreadedText(self.root, padx=5, pady=5, bg=colour_map['background'], fg=colour_map['plaintext'], insertbackground="White", font="CodeFont", yscrollcommand=self.y_scroll.set, width=100, height=20, bd=0, undo=True, autoseparators=True, maxundo=50) self.text.grid(row=0, column=1, sticky="nsew") self.y_scroll.config(command=self.text.yview) self.text.focus_set() # Create box for line numbers self.linenumbers = LineNumbers(self.text, width=25, bg=colour_map['background'], bd=0, highlightthickness=0) self.linenumbers.grid(row=0, column=0, sticky='nsew') # Docstring prompt label self.prompt = TextPrompt(self.text) # Key bindings (Use command key on Mac) ctrl = "Command" if SYSTEM == MAC_OS else "Control" self.text.bind("<Return>", self.newline) self.text.bind("<BackSpace>", self.backspace) self.text.bind("<Delete>", self.delete) self.text.bind("<Tab>", self.tab) self.text.bind("<Key>", self.keypress) self.text.bind("<{}-BackSpace>".format(ctrl), self.delete_word) self.text.bind("<{}-Delete>".format(ctrl), self.delete_next_word) self.text.bind("<{}-Return>".format(ctrl), self.exec_block) self.text.bind("<Alt-Return>", self.exec_line) self.text.bind("<Alt_L>", lambda event: "break") self.text.bind("<{}-a>".format(ctrl), self.selectall) self.text.bind("<{}-period>".format(ctrl), self.killall) self.text.bind("<Alt-period>".format(ctrl), self.releaseNodes) self.text.bind("<{}-c>".format(ctrl), self.edit_copy) self.text.bind("<{}-x>".format(ctrl), self.edit_cut) self.text.bind("<{}-v>".format(ctrl), self.edit_paste) self.text.bind("<{}-bracketright>".format(ctrl), self.indent) self.text.bind("<{}-bracketleft>".format(ctrl), self.unindent) self.text.bind("<{}-equal>".format(ctrl), self.zoom_in) self.text.bind("<{}-minus>".format(ctrl), self.zoom_out) self.text.bind("<{}-z>".format(ctrl), self.undo) self.text.bind("<{}-y>".format(ctrl), self.redo) self.text.bind("<{}-s>".format(ctrl), self.save) self.text.bind("<{}-o>".format(ctrl), self.openfile) self.text.bind("<{}-n>".format(ctrl), self.newfile) self.text.bind("<{}-m>".format(ctrl), self.toggle_menu) self.text.bind("<{}-l>".format(ctrl), self.insert_lambda_symbol) # Change ctrl+h on Mac (is used to close) if SYSTEM == MAC_OS: self.text.bind("<{}-k>".format(ctrl), self.help) self.help_key = "K" else: self.text.bind("<{}-h>".format(ctrl), self.help) self.help_key = "H" # Toggle console button keybind try: self.text.bind("<{}-#>".format(ctrl), self.toggle_console) self.toggle_key = "#" except: self.text.bind("<{}-t>".format(ctrl), self.toggle_console) self.toggle_key = "T" # Save feature variabes self.saved = False self.file = None self.filename = None # --- define bracket behaviour self.bracketHandler = BracketHandler(self) # Set tag names and config for specific colours for tier in tag_weights: for tag_name in tier: self.text.tag_config(tag_name, foreground=colour_map[tag_name]) # --- Create console self.console = console(self, self.default_font) self.console_visible = True sys.stdout = self.console self.text.bind("<Button-1>", lambda e: self.console.canvas.select_clear()) # Store original location of cursor self.origin = "origin" self.text.mark_set(self.origin, INSERT) self.text.mark_gravity(self.origin, LEFT) # Say Hello to the user hello = "Welcome to FoxDot! Press Ctrl+{} for help.".format( self.help_key) print(hello) print("-" * len(hello))
def __init__(self): self.root = Tkinter.Tk() self.root.title(self.title) #窗口面板,用4个面板布局 self.frame = [ Tkinter.Frame(), Tkinter.Frame(), Tkinter.Frame(), Tkinter.Frame() ] #显示消息Text右边的滚动条 self.chatTextScrollBar = Tkinter.Scrollbar(self.frame[0]) self.chatTextScrollBar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y) #显示消息Text,并绑定上面的滚动条 ft = tkFont.Font(family='Fixdsys', size=11) self.chatText = Tkinter.Listbox(self.frame[0], width=70, height=18, font=ft) self.chatText['yscrollcommand'] = self.chatTextScrollBar.set self.chatText.pack(expand=1, fill=Tkinter.BOTH) self.chatTextScrollBar['command'] = self.chatText.yview() self.frame[0].pack(expand=1, fill=Tkinter.BOTH) #标签,分开消息显示Text和消息输入Text label = Tkinter.Label(self.frame[1], height=2) label.pack(fill=Tkinter.BOTH) self.frame[1].pack(expand=1, fill=Tkinter.BOTH) #输入消息Text的滚动条 self.inputTextScrollBar = Tkinter.Scrollbar(self.frame[2]) self.inputTextScrollBar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y) #输入消息Text,并与滚动条绑定 ft = tkFont.Font(family='Fixdsys', size=11) self.inputText = Tkinter.Text(self.frame[2], width=70, height=8, font=ft) self.inputText['yscrollcommand'] = self.inputTextScrollBar.set self.inputText.pack(expand=1, fill=Tkinter.BOTH) self.inputTextScrollBar['command'] = self.chatText.yview() self.frame[2].pack(expand=1, fill=Tkinter.BOTH) #发送消息按钮 self.sendButton = Tkinter.Button(self.frame[3], text='发 送 ', width=10, command=self.sendMessage) self.sendButton.pack(expand=1, side=Tkinter.BOTTOM and Tkinter.RIGHT, padx=15, pady=8) #传文件按钮 self.sendButton = Tkinter.Button(self.frame[3], text='传文件 ', width=10, command=self.sendFile) self.sendButton.pack(expand=1, side=Tkinter.BOTTOM and Tkinter.RIGHT, padx=15, pady=8) #加好友按钮 self.sendButton = Tkinter.Button(self.frame[3], text='加好友', width=10, command=self.addFriends) self.sendButton.pack(expand=1, side=Tkinter.BOTTOM and Tkinter.RIGHT, padx=15, pady=8) #目标好友按钮 self.sendButton = Tkinter.Button(self.frame[3], text='选择好友', width=10, command=self.setTOusr) self.sendButton.pack(expand=1, side=Tkinter.BOTTOM and Tkinter.RIGHT, padx=15, pady=8) #关闭按钮 self.closeButton = Tkinter.Button(self.frame[3], text='关闭 ', width=10, command=self.close) self.closeButton.pack(expand=1, side=Tkinter.RIGHT, padx=15, pady=8) self.frame[3].pack(expand=1, fill=Tkinter.BOTH)
def __init__(self, master, main): self.master = master self.master.title("DALA Settings") self.master.geometry("700x365") master.focus_force() self.main = main self.objects = main.getObjects() #print self.objects self.alg_lbl = Label(self.master, text="Algorithm Variables", font=tkFont.Font(family="Helvetica", size=15)) self.alg_lbl.grid(columnspan=2, row=0, column=0, pady=(5, 10), padx=(7, 0), sticky=W) self.min_match_lbl = Label(self.master, text="Minimum Match Rate:") self.min_match_lbl.grid(row=1, column=1, pady=5, sticky=E) self.min_match_scale = Scale(self.master, from_=0, to_=50, orient=HORIZONTAL, length=500) self.min_match_scale.grid(row=1, column=2, columnspan=3) self.min_match_scale.set(main.getMinMatch()) self.hessian_lbl = Label(self.master, text="Hessian Threshold:") self.hessian_lbl.grid(row=2, column=1, pady=5, sticky=E) self.hessian_scale = Scale(self.master, from_=0, to_=1000, orient=HORIZONTAL, length=500) self.hessian_scale.grid(row=2, column=2, columnspan=3) self.hessian_scale.set(main.getHessian()) self.good_dist_lbl = Label(self.master, text="Good Match Distance:") self.good_dist_lbl.grid(row=3, column=1, pady=5, sticky=E) self.good_dist_scale = Scale(self.master, from_=0, to_=1, orient=HORIZONTAL, resolution=0.01, length=500) self.good_dist_scale.grid(row=3, column=2, columnspan=3) self.good_dist_scale.set(main.getDistance()) self.obj_lbl = Label(self.master, text="Objects", font=tkFont.Font(family="Helvetica", size=15)) self.obj_lbl.grid(columnspan=2, row=4, column=0, padx=(7, 0), pady=(30, 10), sticky="w") self.add_obj__file_btn = Button(self.master, text="Add Object From File", command=self._openAddObjFile, width=20, height=2) self.add_obj__file_btn.grid(row=5, column=1, sticky="w", padx=(5, 0)) self.add_obj_cam_btn = Button(self.master, text="Add Object From Webcam", command=self._openAddObjCam, width=20, height=2) self.add_obj_cam_btn.grid(row=5, column=2, sticky="w", padx=(5, 0)) self.add_obj_bot_btn = Button(self.master, text="Add Object From Robot", command=self._openAddObjBot, width=20, height=2) self.add_obj_bot_btn.grid(row=5, column=3, sticky="w", padx=(5, 0)) self.remove_obj_btn = Button(self.master, text="Remove Object", command=self._openRemoveObj, width=20, height=2) self.remove_obj_btn.grid(row=5, column=4, padx=(5, 0), sticky="w") self.cancel_btn = Button(self.master, text="Cancel", command=self._close, width=20, height=2) self.cancel_btn.grid(row=6, column=0, sticky="w", padx=(5, 0), pady=(40, 0), columnspan=2) self.save_btn = Button(self.master, text="Save", command=self._saveSettings, width=20, height=2) self.save_btn.grid(row=6, column=4, sticky="e", pady=(40, 0))
def __init__(self,master): top=self.top=Toplevel(master) self.l=Label(top,text='Please remove all syringes from the lysate maker',font=tkFont.Font(family='Helvetica', size=24),padx=4,pady=4) self.l.pack() self.b=Button(top,text='All Clear!',height=4,width=12,padx=4,pady=4,font=tkFont.Font(family='Helvetica', size=12),command=self.cleanup) self.b.pack()
def __init__(self, master, settings): self.master = master self.master.title("Add Object From File") self.master.geometry("405x170") master.focus_force() self.settings = settings self.filepath = "" self.filename = "" self.obj_lbl = Label(self.master, text="Ojbect Details", font=tkFont.Font(family="Helvetica", size=15)) self.obj_lbl.grid(columnspan=2, row=0, column=0, pady=(5, 10), padx=(7, 0), sticky="w") self.name_lbl = Label(self.master, text="Object Name:") self.name_lbl.grid(row=1, column=0, sticky="e", pady=5) self.name = Entry(self.master, width=40) self.name.grid(row=1, column=1, sticky="w", columnspan=2) self.path_lbl = Label(self.master, text="Ojbect Image Path:") self.path_lbl.grid(row=2, column=0, sticky="e", pady=5, padx=(5, 0)) self.path = Entry(self.master, width=30) self.path.grid(row=2, column=1, sticky="w") self.path_btn = Button(self.master, text="...", command=self._locateObjImg, width=5) self.path_btn.grid(row=2, column=2, sticky="e", padx=(4, 0)) self.cancel_btn = Button(self.master, text="Cancel", command=self._cancelObjAdd, width=20, height=2) self.cancel_btn.grid(row=3, column=0, sticky="w", pady=(20, 0), padx=(5, 0)) self.save_btn = Button(self.master, text="Add", command=self._saveObjAdd, width=20, height=2) self.save_btn.grid(row=3, column=1, sticky="e", columnspan=2, pady=(20, 0))
def __init__(self, master=None, year=None, month=None, firstweekday=calendar.MONDAY, locale=None, activebackground='#b1dcfb', activeforeground='black', selectbackground='#003eff', selectforeground='white', command=None, borderwidth=1, relief="solid", on_click_month_button=None): """ WIDGET OPTIONS locale, firstweekday, year, month, selectbackground, selectforeground, activebackground, activeforeground, command, borderwidth, relief, on_click_month_button """ if year is None: year = self.datetime.now().year if month is None: month = self.datetime.now().month self._selected_date = None self._sel_bg = selectbackground self._sel_fg = selectforeground self._act_bg = activebackground self._act_fg = activeforeground self.on_click_month_button = on_click_month_button self._selection_is_visible = False self._command = command ttk.Frame.__init__(self, master, borderwidth=borderwidth, relief=relief) self.bind("<FocusIn>", lambda event:self.event_generate('<<DatePickerFocusIn>>')) self.bind("<FocusOut>", lambda event:self.event_generate('<<DatePickerFocusOut>>')) self._cal = get_calendar(locale, firstweekday) # custom ttk styles style = ttk.Style() style.layout('L.TButton', ( [('Button.focus', {'children': [('Button.leftarrow', None)]})] )) style.layout('R.TButton', ( [('Button.focus', {'children': [('Button.rightarrow', None)]})] )) self._font = tkFont.Font() self._header_var = StringVar() # header frame and its widgets hframe = ttk.Frame(self) lbtn = ttk.Button(hframe, style='L.TButton', command=self._on_press_left_button) lbtn.pack(side=LEFT) self._header = ttk.Label(hframe, width=15, anchor=CENTER, textvariable=self._header_var) self._header.pack(side=LEFT, padx=12) rbtn = ttk.Button(hframe, style='R.TButton', command=self._on_press_right_button) rbtn.pack(side=LEFT) hframe.grid(columnspan=7, pady=4) self._day_labels = {} days_of_the_week = self._cal.formatweekheader(3).split() for i, day_of_the_week in enumerate(days_of_the_week): Tkinter.Label(self, text=day_of_the_week, background='grey90').grid(row=1, column=i, sticky=N+E+W+S) for i in range(6): for j in range(7): self._day_labels[i,j] = label = Tkinter.Label(self, background = "white") label.grid(row=i+2, column=j, sticky=N+E+W+S) label.bind("<Enter>", lambda event: event.widget.configure(background=self._act_bg, foreground=self._act_fg)) label.bind("<Leave>", lambda event: event.widget.configure(background="white")) label.bind("<1>", self._pressed) # adjust its columns width font = tkFont.Font() maxwidth = max(font.measure(text) for text in days_of_the_week) for i in range(7): self.grid_columnconfigure(i, minsize=maxwidth, weight=1) self._year = None self._month = None # insert dates in the currently empty calendar self._build_calendar(year, month)