def __init__(self, master, title, text): Toplevel.__init__(self, master=master) self.title(title) fra = Frame(self) fra.grid(row=0, column=0, pady=5, padx=5) self.tx = Text(fra, width=130, height=20, wrap=WORD) scr = Scrollbar(fra, command=self.tx.yview) self.tx.configure(yscrollcommand=scr.set) self.tx.pack(side=LEFT) scr.pack(side=RIGHT, fill=Y) self.tx.bind('<Enter>', lambda e: self._bound_to_mousewheel(e, self.tx)) self.tx.bind('<Leave>', self._unbound_to_mousewheel) self.tx.insert(END, text) self.tx.configure(state='disabled') if platform == "darwin": button_font = Font(family='Arial', size=15) else: button_font = Font(font=Button()["font"]) closeTopolPrevB = Button(self, text='Exit', bg='red', command=self.destroy, font=button_font) closeTopolPrevB.grid(row=1, column=0, pady=5)
def __init__(self, master=None, startLatch=None, stopLatch=None, ghostXfer=None): tk.Frame.__init__(self, master, width=1024, height=600) self.pack(fill=None, expand=False) self.zones = {} self.buttonfont = Font(family="ledfixed", size=30) self.statusfont = Font(family="ledfixed", size=20) self.megafont = Font(family="ledfixed", size=150, weight="bold") self.timer = tk.StringVar() self.timer.set("--.-") self.bmatest = 2 self.currentStatus = tk.StringVar() self.ghost = None # Be sure to define these after instantiating the class self.startLatch = startLatch self.stopLatch = stopLatch self.ghostXfer = ghostXfer self.createLayout() self.refresh_filepicker()
def __init__(self, parent, controller, frames): self.parent = parent self.controller = controller title_font = Font(family='Helvetica', size=15, weight="bold", slant="italic") Label(self.parent, text='Summary', font=title_font).pack(side="top", fill="x", pady=10) self.widths = [18, 40, 60] self.frame = Frame(self.parent) self.frame.pack() font = Font(weight="bold", slant="italic") # family='Helvetica', for col, txt in enumerate(["Section", "Parameters", "cmd"]): Label(self.frame, text=txt, relief=RIDGE, width=int(self.widths[col]), height=3, font=font).grid(row=0, column=col) curr_row = 1 for F in frames: num_rows = self.get_summary(curr_row, F.get_data(), F.title, F.get_cmd()) curr_row += num_rows Button(self.parent, text="Exit", command=self.parent.destroy).pack(side=BOTTOM)
def add_assembly(): """添加组件""" init() buy_house_static = Label(master, text=u'购房: ', font=Font(size=15)) buy_house_static.place(anchor=u'nw', x=440, y=50) buy_car_static = Label(master, text=u'购车: ', font=Font(size=15)) buy_car_static.place(anchor=u'nw', x=440, y=75) age_static = Label(master, text=u'年龄: ', font=Font(size=15)) age_static.place(anchor=u'nw', x=440, y=100) height_static = Label(master, text=u'身高: ', font=Font(size=15)) height_static.place(anchor=u'nw', x=440, y=125) salary_static = Label(master, text=u'工资: ', font=Font(size=15)) salary_static.place(anchor=u'nw', x=440, y=150) education_static = Label(master, text=u'学历: ', font=Font(size=15)) education_static.place(anchor=u'nw', x=440, y=175) company_static = Label(master, text=u'公司: ', font=Font(size=15)) company_static.place(anchor=u'nw', x=440, y=200) industry_static = Label(master, text=u'行业: ', font=Font(size=15)) industry_static.place(anchor=u'nw', x=440, y=225) school_static = Label(master, text=u'学校: ', font=Font(size=15)) school_static.place(anchor=u'nw', x=440, y=250) position_static = Label(master, text=u'职位: ', font=Font(size=15)) position_static.place(anchor=u'nw', x=440, y=275) previous = Button(master, text=u'上一个', command=handle_previous) previous.place(anchor=u'nw', x=10, y=490) next = Button(master, text=u'下一个', command=handle_next) next.place(anchor=u'nw', x=520, y=490)
def _tk_redraw_canvas(self, width, height): if self._canvas: self._canvas.destroy() self._fnormal = Font(family='Monospace', size=13) self._fbold = Font(family='Monospace', weight='bold', size=13) self._fitalic = Font(family='Monospace', slant='italic', size=13) self._fbolditalic = Font(family='Monospace', weight='bold', slant='italic', size=13) self._colsize = self._fnormal.measure('A') self._rowsize = self._fnormal.metrics('linespace') self._canvas = Canvas(self._root, width=self._colsize * width, height=self._rowsize * height) self._tk_fill_region(0, height - 1, 0, width - 1) self._cursor_row = 0 self._cursor_col = 0 self._scroll_top = 0 self._scroll_bot = height - 1 self._scroll_left = 0 self._scroll_right = width - 1 self._width, self._height = ( width, height, ) self._canvas.pack()
def __init__(self, parent): tk.Frame.__init__(self, parent) self.parent = parent self.custom_font = Font(family='Times', size=17) self.label_font = Font(family='URW Chancery L', size=16) self.default_font = Font(family='Century Schoolbook L', size=17) self.style = ttk.Style() self.initialize()
def set_font(self, fontdesc): self.text.config(font=fontdesc) normal_font = Font(self.text, self.text.cget('font')) self.bold_font = bold_font = Font(self.text, self.text.cget('font')) self.bold_font.config(weight='bold') self.char_size = normal_font.measure('M') text = self.text text.tag_config('output', font=normal_font) text.tag_config('Prompt', foreground='#0000cc', font=normal_font) text.tag_config('PromptNum', foreground='#0000bb', font=bold_font) text.tag_config('OutPrompt', foreground='#cc0000', font=normal_font) text.tag_config('OutPromptNum', foreground='#bb0000', font=bold_font)
def open(self): if self.is_open == False: self.window = Toplevel(self.parent) self.window.geometry("370x380+" + str(self.parent.control_panel_xpos) + "+" + str(self.parent.control_panel_ypos)) self.window.wm_title("CK control panel") self.window.configure(bg="black") print("loading control window") self.window.protocol('WM_DELETE_WINDOW', self.cp_close) self.pgm_box = [] self.pgm_down = [] self.pgm_up = [] self.inst_button = [] self.k1 = [] self.k2 = [] self.fish = [] self.fishman_strings = ['All','E','A','D','G','B','e'] self.font_big = Font(family="Ariel", size=24) self.font_med = Font(family="Ariel", size=18) self.button_play = Button(self.window, text="Play", command=lambda: self.parent.q(self.parent.ls.playback(['play'])),bg="#003366", fg="white", width=5) self.button_play.grid(row=5, column=1) self.button_stop = Button(self.window, text="Stop", command=lambda: self.parent.q(self.parent.ls.playback(['stop'])),bg="#003366", fg="white", width=5) self.button_stop.grid(row=5, column=2) #self.sv = StringVar() #self.sv.trace("w", lambda name, index, mode, sv=self.sv: self.text_changed()) self.loops_button = Button(self.window, text="Loops", command=lambda: self.parent.q(self.parent.ls.select(["Loops",1])),bg="#003366", fg="white", width=5) self.loops_button.grid(row=1, column=7) row_offset = 2 for i,instrument in enumerate(['Kontakt','GuitarIn','Massive','FM8']): print ("br",i,instrument) self.inst_button.append(Button(self.window, text=instrument, command=lambda l_inst = instrument: self.parent.q(self.parent.ls.select([l_inst])),bg="#003366", fg="white", width=len(instrument))) self.inst_button[i].grid(row=i+row_offset, column=7) self.pgm_up.append(Button(self.window, text="Next\nPgm", command=lambda li = i: self.program_button(li,1),bg="#003366", fg="white", width=5)) self.pgm_up[i].grid(row=i+row_offset, column=6) self.pgm_box.append(Entry(self.window, width=3,exportselection=False, bg="black", fg="lightblue", font=self.font_big, insertbackground="white")) #, textvariable = self.sv, borderwidth=0) self.pgm_box[i].grid(row=i+row_offset, column=5,sticky=W) self.pgm_box[i].insert(0,"1") self.pgm_down.append(Button(self.window, text="Prev\nPgm", command=lambda li = i: self.program_button(li,-1),bg="#003366", fg="white", width=5)) self.pgm_down[i].grid(row=i+row_offset, column=4) self.k2.append(Button(self.window, text="K2", command=lambda l_inst = instrument: self.parent.q(self.parent.ls.output(['KeysIn2',l_inst])),bg="#003366", fg="white", width=5)) self.k2[i].grid(row=i+row_offset, column=3) self.k1.append(Button(self.window, text="K1", command=lambda l_inst = instrument: self.parent.q(self.parent.ls.output(['KeysIn1',l_inst])),bg="#003366", fg="white", width=5)) self.k1[i].grid(row=i+row_offset, column=2) self.fish.append(Button(self.window, text="Fish", command=lambda l_inst = instrument: self.parent.q(self.parent.ls.output(['Fishman',l_inst])),bg="#003366", fg="white", width=5)) self.fish[i].grid(row=i+row_offset, column=1) self.window.focus_set()
def __init__(self): super(Tkinter, self).__init__() #Inicialitzem la finestra emb les mides i el titol self.app1 = Tk() self.app1.title("Control del consum electric") self.app1.geometry("800x450") self.fondo = PhotoImage(file="fondo.gif") self.lbl_Fondo = Label(self.app1, image=self.fondo).place(x=0,y=0) #Importem les classes dels altres arxius self.database = Database() self.sensor = PowerServer() #TIpus i mides de lletres que utilitzarem self.myFont = Font(family="Verdana", size=16) self.myFont2 = Font(family="Verdana",weight="bold", size=20) self.myFont3 = Font(family="Verdana",weight="bold", size=26) self.myFont4 = Font(family="Verdana", size=12, weight="bold") #Definim les variables de lectura i la seva estructura self.sensor1 = StringVar() self.sensor2 = StringVar() self.sensor3 = StringVar() self.sensor1.set("- - "+" W") self.sensor2.set("- -"+" W") self.sensor3.set("- -"+" W") #Insertem el text de les instruccions a seguir lbl = Label(self.app1,text=" Instruccions d'us:" "\n\n - Primer de tot assegura't\n" " de tenir conectades les pinces que utilitzaras.\n" " A la part superior de les pinces hi ha un fletxa\n" " que s'ha de col·locar en direcció de la corrent\n" " - Si disposes de connexió a internet configura-la\n" " a la part superior de l'esquerra de la pantalla", justify=LEFT, font=self.myFont,bg="khaki", highlightbackground="gold3", highlightthickness=3, padx=10, ) lbl.place(x=150,y=100) #Boto per continuar despres de llegir les instruccions button_continuar = Button(self.app1,text="Continuar",font=self.myFont,command=self.tipus_instalacio, bg="khaki", bd=3, activebackground="gold",relief=RIDGE, overrelief=GROOVE, highlightbackground="gold3", highlightthickness=3 ) button_continuar.place(x=350,y=350) self.app1.mainloop()
def __init__(self, master=None): Frame.__init__(self, master) self.master.title("Network Simulator Log") self.text = ScrolledText(self) self.text.pack(fill=BOTH, expand=1) self.pack(fill=BOTH, expand=1) self.text.config( background="black", foreground="white", font=Font(family="Courier", weight="bold"), # state=DISABLED, wrap=NONE, ) self.text.tag_config("DEBUG", foreground="green") self.text.tag_config("ERROR", foreground="red") self.text.tag_config("CRITICAL", foreground="red") self.text.tag_config("EXCEPTION", foreground="red") self.text.tag_config("WARNING", foreground="yellow") self.text.tag_config("INFO", foreground="white") self.text.bind("<Key>", lambda e: 'break') self.text.bind("<Return>", self._clear) self.queue = Queue() self._update()
def __init__(self): self.app = Tk() self.app.title('TicTacToe') self.app.resizable(width=False, height=False) self.board = Board() self.font = Font(family="Helvetica", size=32) self.buttons = {} for x, y in self.board.fields: handler = None # handler = lambda x = x, y = y: self.move(x, y) button = Button(self.app, command=handler, font=self.font, width=2, height=1) button.grid(row=y, column=x) self.buttons[x, y] = button handler = lambda: self.reset() button = Button(self.app, text='reset', command=handler) button.grid(row=self.board.size + 1, column=0, columnspan=self.board.size, sticky="WE") handler = lambda: self.start() button = Button(self.app, text='start', command=handler) button.grid(row=self.board.size + 2, column=0, columnspan=self.board.size, sticky="WE") self.start_button = button self.update()
def add_residues(self): self.residue_labels = [] self.selected_residues = [] self.residues = control.getResidueInChain(self.current_chain) label_width = 12 # width of each residue label label_height = 25 # height of each residue label line_space = 5 # space between lines number_line = int(460 / label_width) # number of labels each line for index, r in enumerate(self.residues): info = control.residueSingleLetter(r[1]) #print(index, info) rowIndex = int(index / number_line) columnIndex = index - rowIndex * number_line l = tk.Label(self.frame2, text=info, bg="SlateGray2", fg="blue4", font=Font(family="Times", size=6), justify="left") l.place(x=5 + columnIndex * label_width, y=(label_height + line_space) * rowIndex, height=label_height, width=label_width, anchor="nw") l.bind( '<Button-1>', lambda event, n=r[0], i=index: self.show_residue(event, n, i)) self.residue_labels.append(l)
def _init_fonts(self, root): # See: <http://www.astro.washington.edu/owen/ROTKFolklore.html> self._sysfont = Font(font=Button()["font"]) root.option_add("*Font", self._sysfont) # TWhat's our font size (default=same as sysfont) self._size = IntVar(root) self._size.set(self._sysfont.cget('size')) self._boldfont = Font(family='helvetica', weight='bold', size=self._size.get()) self._font = Font(family='helvetica', size=self._size.get()) if self._size.get() < 0: big = self._size.get() - 2 else: big = self._size.get() + 2 self._bigfont = Font(family='helvetica', weight='bold', size=big)
def __init__(self, canvas, drs, **attribs): self._drs = drs self._canvas = canvas canvas.font = Font( font=canvas.itemcget(canvas.create_text(0, 0, text=''), 'font')) canvas._BUFFER = 3 self.bbox = (0, 0, 0, 0)
def calculate_text_width(text, family=TREEVIEW_FONT_NAME, size=TREEVIEW_FONT_SIZE): # create the font font = Font(family=family, size=size) # measure the width of the text and return return font.measure(text)
def game(self): self.score = 0 self.w = Canvas(self.root, width=750, height=500, relief="flat", highlightbackground="grey", highlightthickness=10) self.frame1.destroy() self.frame2.destroy() self.root.configure(width=1000, padx=10) self.root.pack_propagate(0) self.w.configure(background="black") self.w.pack(side="left") self.w.create_line(300, 250, 450, 250, width=10, fill="teal") self.scoreC = Label(self.root, text="Score\n" + str(self.score), bg="black", fg="teal", padx=25, pady=35, font=Font(family="comic sans MS", size=25)) self.head = self.w.create_line(450, 250, 455, 250, width=10, fill="white") self.scoreC.pack(side="top") self.root.bind("<Up>", self.callup) self.root.bind("<Down>", self.calldown) self.root.bind("<Right>", self.callright) self.root.bind("<Left>", self.callleft) self.createFood() self.right(0)
def __init__(self, wdw, sols): """ Stores the list of solutions in sols and defines the layout of the GUI. """ wdw.title('solutions scroller') self.sols = sols self.cursor = 0 self.lbl = Label(wdw, text="solution : ") self.lbl.grid(row=0, column=0, sticky=E) self.ent = Entry(wdw) self.ent.grid(row=0, column=1, stick=W) self.ent.insert(INSERT, "0 of %d" % len(sols)) self.myft = Font(family="Courier New", size=12, weight="normal") self.mlen = self.myft.measure("M") lines = sols[0].split('\n') self.width = max([len(line) for line in lines]) self.display = StringVar() self.display.set(self.sols[0]) self.mess = Message(wdw, textvariable=self.display, \ font=self.myft, width=self.width*self.mlen, background='white') self.mess.grid(row=1, column=0, columnspan=2) self.btnext = Button(wdw, command=self.next, text='next') self.btnext.grid(row=2, column=1, sticky=W + E) self.btprev = Button(wdw, command=self.previous, text='previous') self.btprev.grid(row=2, column=0, sticky=W + E)
def __init__(self, master, closeWin, restartAll, saveImage, statusStr, twoLines=False): tk.Frame.__init__( self, master, bd=5, relief='sunken' ) # explicitly initialize base class and create window self.master = master self.closeWin, self.restartAll, self.saveImage, self.statusStr \ = closeWin, restartAll, saveImage, statusStr # create buttons monospaceFont = Font(family="Courier", weight='bold', size=12) tk.Label(self, textvariable=self.statusStr, font=monospaceFont).pack( side="bottom" if twoLines else "right", pady=5) tk.Button(self, text="Quit (esc)", command=self.closeWin).pack(side="left", pady=5) tk.Button(self, text="Restart (R)", command=self.restartAll).pack(side=tk.LEFT) tk.Button(self, text="Save Map", command=self.saveImage).pack(side=tk.LEFT) # bind keyboard inputs to functions master.bind( '<Escape>', lambda event: self.closeWin()) # escape exits program after prompt master.bind('<Shift-R>', lambda event: self.restartAll() ) # shift and capital R does a soft reset
def __init__(self, master, text, background=None, font=None, familiy=None, size=None, underline=True, visited_fg = "#551A8B", normal_fg = "#0000EE", visited=False, action=None): self._visited_fg = visited_fg self._normal_fg = normal_fg if visited: fg = self._visited_fg else: fg = self._normal_fg if font is None: default_font = nametofont("TkDefaultFont") family = default_font.cget("family") if size is None: size = default_font.cget("size") font = Font(family=family, size=size, underline=underline) Label.__init__(self, master, text=text, fg=fg, cursor="hand2", font=font) if background is None: background = get_background_of_widget(master) self.configure(background=background) self._visited = visited self._action = action self.bind("<Button-1>", self._on_click)
def __init__(self, Width, CallStack, DbIf): CallStack.info("DeckFrame.__init__: Called") self._callstack = CallStack tk.Frame.__init__(self, width=Width) module_log = logging.FileHandler("DeckFrame.txt") self._log = logging.getLogger('DeckFrame') self._log.addHandler(module_log) self.canvas= tk.Canvas(width=300, height=1200) self.canvas.grid(row=1, column=0, rowspan=10) self._deckset = DeckSet(self._callstack, DbIf) self._deckset.LoadDecks() x_coord = 0 y_coord = 0 row_count = 2 for deck in self._deckset._deckset: item = self.canvas.create_image(x_coord, y_coord, image=deck._tk_image, anchor="nw", tags="deck") self.canvas.create_text((110, (y_coord + 325)), text=deck._name, font=Font(size=15, weight="bold")) y_coord = y_coord + 370 row_count = row_count + 1 self.scroll = tk.Scrollbar(orient="vertical") self.scroll.config(command=self.canvas.yview) self.canvas.config(scrollregion=(0, 0, 10000, (row_count * 450)), yscrollcommand=self.scroll.set) self.scroll.grid(row=1, column=1, rowspan=5, sticky="n s e") CallStack.info("DeckFrame.__init__: Returned")
def getFont(name, size, style): """Create a font object. Arguments name -- font name size -- font size style -- font style; any combination of b, i, u, s: b -> bold i -> italic u -> underline s -> strikeout """ if ('b' in style): weight = 'bold' else: weight = 'normal' if ('i' in style): slant = 'italic' else: slant = 'roman' underline = ('u' in style) overstrike = ('s' in style) return Font(family=name, size=size, weight=weight, slant=slant, underline=underline, overstrike=overstrike)
def __init__(self,parent,frames=None,aligns=None,weights=None,**kwargs): Frame.__init__(self,parent,**kwargs) self.numberOfRows=0 self.aligns = aligns if not self.aligns: self.aligns = ["left","left","left","left","left","left"] if not weights: weights=[1,1,1,1] if frames==None: self.frames=["one","two","three","four","five","six"] else: self.frames=frames # for i in range(0,len(self.frames)): # self.frames[i]=Frame(self) # self.frames[i].grid(side=LEFT,expand=1,fill=BOTH) self.textBoxes=[] for i in range(0,len(self.frames)): self.textBoxes.append(Text(self,bd=0,width=0,state='disabled')) self.textBoxes[-1].grid(row=0,column=i,sticky=W+E+N+S) self.textBoxes[-1].tag_configure("right",justify="right",wrap=NONE) self.textBoxes[-1].tag_configure("center",justify="center",wrap=NONE) self.textBoxes[-1].tag_configure("left",justify="left",wrap=NONE) self.textBoxes[-1].tag_configure("underline",underline=True) self.grid_columnconfigure(i,weight=weights[i]) self.grid_rowconfigure(0,weight=1) self.boldFont = Font(self.textBoxes[0],self.textBoxes[0].cget('font')) self.boldFont.configure(weight='bold') for i in self.textBoxes: i.tag_configure("bold",font=self.boldFont)
def __init__(self): self.app = Tk() self.app.title('TicTacToe') self.app.resizable(width=False, height=False) self.font = Font(family="Helvetica", size=100) self.board = Board("ai") self.buttons = {} self.backBtn = None self.gameOverLabel = None #menu buttons self.mode = "" self.aiBtn = None self.hostBtn = None self.joinBtn = None #networking constructs self.conn = None self.addr = None self.TCP_IP = '127.0.0.1' self.TCP_PORT = 5007 self.BUFFER_SIZE = 128 self.s = None # begin the menu self.menuScreen()
def GetFont(self, root, configType, section): """Retrieve a font from configuration (font, font-size, font-bold) Intercept the special value 'TkFixedFont' and substitute the actual font, factoring in some tweaks if needed for appearance sakes. The 'root' parameter can normally be any valid Tkinter widget. Return a tuple (family, size, weight) suitable for passing to tkinter.Font """ family = self.GetOption(configType, section, 'font', default='courier') size = self.GetOption(configType, section, 'font-size', type='int', default='10') bold = self.GetOption(configType, section, 'font-bold', default=0, type='bool') if (family == 'TkFixedFont'): if TkVersion < 8.5: family = 'Courier' else: f = Font(name='TkFixedFont', exists=True, root=root) actualFont = Font.actual(f) family = actualFont['family'] size = actualFont['size'] if size <= 0: size = 10 # if font in pixels, ignore actual size bold = actualFont['weight']=='bold' return (family, size, 'bold' if bold else 'normal')
def fillInUI(self, parent): label = Tk.Label(parent, text="Warning: clipping is turned on (see Side View" " tool) and will severely slow down POV-Ray raytracing.", justify='left', height=2) import tkFont font = tkFont.Font(root=parent, font=label.cget('font')) label.config(wraplength=(self.text_width * font.measure('n'))) label.grid(row=0, columnspan=2, sticky=Tk.W, pady=5) off = Tk.Button(parent, text="Turn off clipping", command=self.__turnOff) off.grid(row=1, column=0, pady=1) if ClipWarning.__dsVar is None: ClipWarning.__dsVar = Tk.IntVar(chimera.tkgui.app) ClipWarning.__dsVar.set(False) ds = Tk.Checkbutton(parent, variable=ClipWarning.__dsVar, text="Don't show dialog again") from tkFont import Font font = Font(font=ds.cget('font')) font.config(size=int(0.75*float(font.cget('size'))+0.5), weight='normal') ds.config(font=font) ds.grid(row=1, column=1, sticky=Tk.SE, pady=1) parent.rowconfigure(0, weight=1) parent.columnconfigure(0, weight=1)
def show(self, window): frame = Frame(window) frame.pack() title_font = Font(family='Helvetica', size=15, weight="bold", slant="italic") Label(frame, text='Material composition', font=title_font).pack(side="top", fill="x", pady=10) Label(frame, text="Provide the material's composition by:").pack() OptionMenu(frame, self.type_var, "Number of atoms", "Mass fraction", command=self.set_fraction_input_method).pack() Label(frame, text="(hover over the headers for explanation)").pack() elements_frame = Frame(frame) symbol = Label(elements_frame, text="Element (e.g. Au)") symbol.grid(row=0, column=0) ToolTip(symbol, "The chemical symbol of the element\nfor example for carbon use C") self.num_atoms_label = Label(elements_frame, text="Num atoms") self.fraction_label = Label(elements_frame, text="Mass frac") ToolTip(self.fraction_label, "The fraction of mass (between 0 and 1)") self.num_atoms_label.grid(row=0, column=1) elements_frame.pack() if len(self.elements_dict) == 0: self.add_element_and_show(elements_frame) else: for row in self.elements_dict.keys(): self.show_element(elements_frame, row) Button(frame, text="Add element", command=lambda: self.add_element_and_show(elements_frame)).pack() density_frame = Frame(frame) Label(density_frame, text="Density (optional):").grid(row=0, column=0) Entry(density_frame, textvariable=self.density).grid(row=0, column=1) Label(density_frame, text=u"[g/cm\xb3]").grid(row=0, column=2) density_frame.pack()
def __init__(self, drs, size_canvas=True, canvas=None): """ :param drs: ``AbstractDrs``, The DRS to be drawn :param size_canvas: bool, True if the canvas size should be the exact size of the DRS :param canvas: ``Canvas`` The canvas on which to draw the DRS. If none is given, create a new canvas. """ master = None if not canvas: master = Tk() master.title("DRT") font = Font(family='helvetica', size=12) if size_canvas: canvas = Canvas(master, width=0, height=0) canvas.font = font self.canvas = canvas (right, bottom) = self._visit(drs, self.OUTERSPACE, self.TOPSPACE) width = max(right + self.OUTERSPACE, 100) height = bottom + self.OUTERSPACE canvas = Canvas(master, width=width, height=height) #, bg='white') else: canvas = Canvas(master, width=300, height=300) canvas.pack() canvas.font = font self.canvas = canvas self.drs = drs self.master = master
def redraw(self, camera_transform, canvas): screen_coords = self.world_vertices_np.dot(camera_transform[:-1].T) if self.scale: scale = np.linalg.norm(screen_coords[1] - screen_coords[2]) new_size = int(self.size * scale) if new_size != self.current_size and new_size % 5 == 0 and new_size <= 70: self.current_size = new_size self.cleanup(canvas) if new_size >= 10: textId = canvas.create_text(0, 0, fill=self.color, text=self.text, font=Font(size=new_size), anchor=tk.NW) canvas.addtag_withtag(self.tag, textId) self.element_ids = (textId, ) else: new_size = 10 elem_id, = self.element_ids x, y = screen_coords[0] canvas.coords(elem_id, x, y)
def __init__(self): self.app = Tk() self.app.title('Connect4') self.app.resizable(width=False, height=False) self.board = Board() self.buttons = {} self.frame = Frame(self.app, borderwidth=1, relief="raised") self.tiles = {} for x in range(self.board.width): handler = lambda x=x: self.move(x) button = Button(self.app, command=handler, font=Font(family="Helvetica", size=14), text=x + 1) button.grid(row=0, column=x, sticky="WE") self.buttons[x] = button self.frame.grid(row=1, column=0, columnspan=self.board.width) for x, y in self.board.fields: tile = Canvas(self.frame, width=60, height=50, bg="navy", highlightthickness=0) tile.grid(row=self.board.height - 1 - y, column=x) self.tiles[x, y] = tile handler = lambda: self.reset() self.restart = Button(self.app, command=handler, text='reset') self.restart.grid(row=2, column=0, columnspan=self.board.width, sticky="WE") self.update()
def main(): ''' Display with tkinter ''' master = Tk() master.withdraw() clipboard_text = master.clipboard_get() meaning_text = getMeanings(clipboard_text) if meaning_text is not None or meaning_text != '': word_heading = '' word_meaning = '' i = 1 for words, elements in meaning_text.items(): word_heading = str(words) + ":" + "\n" if elements is None: word_meaning = "No meaning(s) available." break for parts_of_speech, meaning in elements.items(): meaning_text = appendAllMeanings(meaning) word_meaning += str( i ) + ". " + parts_of_speech + ": \n" + meaning_text + "\n\n" i += 1 # create frame for window dict_frame = Frame(master, relief=GROOVE, width=50, height=100, bd=1) dict_frame.place(x=10, y=10) # create scrollbar scrollbar = Scrollbar(master) scrollbar.pack(side=RIGHT, fill=Y) # create text box txt = Text(master, wrap=WORD, background="#e6ffff") txt.pack(expand=1, fill=BOTH) # create fonts myFont = Font(family="Times New Roman", size=12) txt.tag_configure("bold", font="wieght:bold") txt.configure(font=myFont) # insert text txt.insert(END, "\n") txt.insert(END, word_heading + "\n", "bold") txt.insert(END, word_meaning + "\n") # configure text widget txt.configure(state=DISABLED) txt.config(yscrollcommand=scrollbar.set) # assign scrollbar scrollbar.config(command=txt.yview) # show the tkinter window master.deiconify() mainloop()