我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用tkinter.font.Font()。
def __init__(self, root): self.game = chess_model.game self.do_replay = False # photo_images: the PhotoImage objects, one per *type* of piece, that # are loaded from disk. self.photo_images = {} # displayed_images: the actual individual displayed spites, one per # *piece*, that are each positioned on an actual square. self.displayed_images = {} self.custom_font = tkFont.Font(family="{Times}",size=16) self.bigger_font = tkFont.Font(family="{Times}",size=20) self.root = root self.root.title("Stephen's Crazy Chess") self.root.bind('<Return>', self.start_game) self.top = ttk.Frame(self.root) self.top.pack() self.setup() self._drag_stuff = {'x': 0, 'y': 0, 'piece': None} self.center()
def body(self, master): ttk.Style().configure("White.TLabel", background="white") ttk.Label(master, image=self.logo, justify="center", style="White.TLabel").pack(pady=10) title = font.Font(family=font.nametofont("TkDefaultFont").cget("family"), size=15, weight="bold") ttk.Label(master, text=(self.program_title, self.version), font=title, justify="center", style="White.TLabel").pack() ttk.Label(master, text=self.description, wraplength=230, justify="center", style="White.TLabel").pack() ttk.Label(master, text=self.copyright_text, justify="center", style="White.TLabel").pack() link = pk.Hyperlink(master, text="Visit the project on GitHub", link="https://github.com/DeflatedPickle/Quiver") link.configure(background="white", justify="center") link.pack(pady=3) link._font.configure(size=10)
def _load_browse_data(self): print("reloading room/zones browse data") self.data = self._get_room_list() self.tree.delete(*self.tree.get_children()) self.tree_index = dict() for idx in range(len(self.dataCols)): self.tree.column(self.dataCols[idx], width=10) for item in self.data: index = self.tree.insert('', 'end', values=item[1:]) self.tree_index[index] = item if item[2] == 'active': self.tree.selection_add(index) for idx in range(len(self.dataCols)-1): i_width = Font().measure(item[idx+1]) + 10 if self.tree.column(self.dataCols[idx], 'width') < i_width: self.tree.column(self.dataCols[idx], width=i_width)
def init_SortingButton(): fontemp = font.Font(bo_Frame, size=12, weight='bold') m1_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? BOX OFFICE ?? ??\n({0} ??)".format(yesterday), command=lambda: searchButtonAction(1)) m1_button.place(x=730, y=5) m2_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? ?? ?", command=lambda: sortingButtonAction(1)) m2_button.place(x=5, y=350) m3_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? ???", command=lambda: sortingButtonAction(2)) m3_button.place(x=127, y=350) m4_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? ?? ?", command=lambda: sortingButtonAction(3)) m4_button.place(x=250, y=350) m5_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? ???", command=lambda: sortingButtonAction(4)) m5_button.place(x=382, y=350)
def SearchMenu(): global list_movieData, dic_detailData, s1_ListBox, s2_ListBox global dic_photo, photo list_movieData = [] dic_detailData = {} bgLabel = Label(sc_Frame, width=600, height=600, bg='white') bgLabel.place(x=0, y=0) init_searchInputLabel() fontemp = font.Font(sc_Frame, size=12, weight='bold') s1_ListBox = Listbox(sc_Frame, font=fontemp, width=37, height=18, borderwidth=2, relief='ridge') s1_ListBox.place(x=5, y=75) s2_ListBox = Listbox(sc_Frame, font=fontemp, width=37, height=10, borderwidth=2, relief='ridge') s2_ListBox.place(x=5, y=450) s1_ListBox.bind('<<ListboxSelect>>', info_event)
def init_loginLabel(): global IDInputLabel, PWInputLabel fontemp = font.Font(sm_Frame, size=40, weight='bold') fontemp2 = font.Font(sm_Frame, size=30, weight='bold') fontemp3 = font.Font(sm_Frame, size=20, weight='bold') titleLabel = Label(sm_Frame, font=fontemp, text="SEND E-MAIL", bg='white') titleLabel.place(x=470, y=150) IDLabel = Label(sm_Frame, font=fontemp2, text="ID", bg='white') IDLabel.place(x=350, y=250) IDInputLabel = Entry(sm_Frame, font=fontemp2, width=18, borderwidth=3, relief='ridge', fg='blue') IDInputLabel.place(x=450, y=250) PWLabel = Label(sm_Frame, font=fontemp2, text="PW", bg='white') PWLabel.place(x=335, y=350) PWInputLabel = Entry(sm_Frame, font=fontemp2, width=18, borderwidth=3, relief='ridge', fg='blue', show='*') PWInputLabel.place(x=450, y=350) sendButton = Button(sm_Frame, font=fontemp3, text="Send", command=lambda: sendMail()) sendButton.place(x=600, y=550) #============================================
def __init__(self, parent, text="", link="https://github.com/DeflatedPickle/pkinter", *args): ttk.Label.__init__(self, parent, foreground="blue", cursor="arrow", *args) self.parent = parent self._text = text self._link = link self._font = font.Font(self, self.cget("font")) self.configure(font=self._font) if self._text == "": self.configure(text=self._link) else: self.configure(text=self._text) self.bind("<Enter>", self._enter, "+") self.bind("<Leave>", self._leave, "+") self.bind("<Button-1>", self._button, "+") self.bind("<ButtonRelease-1>", self._button_released, "+")
def _nvimtk_config(self, *args): '''required config''' # Hide tkinter cursor self.config(insertontime=0) # Remove Default Bindings and what happens on insert etc bindtags = list(self.bindtags()) bindtags.remove("Text") self.bindtags(tuple(bindtags)) self.bind('<Key>', self.nvim_handler.tk_key_pressed) self.bind('<Button-1>', lambda e: self.focus_set()) # The negative number makes it pixels instead of point sizes size = self.make_font_size(13) self._fnormal = tkfont.Font(family='Monospace', size=size) self._fbold = tkfont.Font(family='Monospace', weight='bold', size=size) self._fitalic = tkfont.Font(family='Monospace', slant='italic', size=size) self._fbolditalic = tkfont.Font(family='Monospace', weight='bold', slant='italic', size=size) self.config(font=self._fnormal, wrap=tk.NONE) self.nvim_handler._colsize = self._fnormal.measure('M') self.nvim_handler._rowsize = self._fnormal.metrics('linespace')
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): """Sets up the window and widgets.""" EasyFrame.__init__(self, title = "Image Demo") self.setResizable(False) imageLabel = self.addLabel(text = "", row = 0, column = 0, sticky = N+S+W+E) textLabel = self.addLabel(text = "Smokey the cat", row = 1, column = 0, sticky = N+S+W+E) # Load the image and associate it with the image label. self.image = PhotoImage(file = "smokey.gif") imageLabel["image"] = self.image # Set the font and color of the caption. font = Font(family = "Verdana", size = 20, slant = "italic") textLabel["font"] = font textLabel["foreground"] = "blue"
def insert_ttk_label(self, anchor: tk.W or tk.CENTER or tk.E or str=None, background: str="", font: font.Font=None, foreground: str="", justify: tk.LEFT or tk.CENTER or tk.RIGHT or str=None, padding: list=[], relief: tk.FLAT or tk.RAISED or tk.SUNKEN or tk.GROOVE or tk.RIDGE or str="flat", text: str="", wraplength: int=0, index: int or str="end", *args, **kwargs): """Insert a ttk.Label into the game.""" widget = ttk.Label(self.text, anchor=anchor, background=background, font=font, foreground=foreground, justify=justify, padding=padding, relief=relief, text=text, wraplength=wraplength, **kwargs) self.text.window_create(index, window=widget) return widget
def __init__(self, textwidget, filetype_name_getter): self.textwidget = textwidget self._get_filetype_name = filetype_name_getter self.pygmentizer = PygmentizerProcess() # the tags use fonts from here self._fonts = {} for bold in (True, False): for italic in (True, False): # the fonts will be updated later, see _on_config_changed() self._fonts[(bold, italic)] = tkfont.Font( weight=('bold' if bold else 'normal'), slant=('italic' if italic else 'roman')) config.connect('pygments_style', self._on_config_changed) config.connect('font_family', self._on_config_changed) config.connect('font_size', self._on_config_changed) self._on_config_changed() self.textwidget.after(50, self._do_highlights)
def __init__(self, master, title, main, sub, **kwargs): super().__init__(master=master, **kwargs) self.configure(borderwidth=3, relief='groove') self._title_font = font.Font(family='mono', size=-15) self._main_font = font.Font(family='mono', size=-30, weight='bold') self._sub_font = font.Font(family='mono', size=-15) self._title_string = StringVar(value=title) self._title_label = ttk.Label(self, textvariable=self._title_string, font=self._title_font) self._main_string = StringVar(value=main) self._main_label = ttk.Label(self, textvariable=self._main_string, font=self._main_font) self._sub_string = StringVar(value=sub) self._sub_label = ttk.Label(self, textvariable=self._sub_string, font=self._sub_font) self._title_label.grid(column=0, row=0, sticky=N + S + W, padx=15, pady=5) self._main_label.grid(column=0, row=1, sticky=N + S + W, padx=10, pady=5) self._sub_label.grid(column=0, row=2, sticky=N + S + W, padx=15, pady=5) self.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1)
def addLine(self, settingsList, dpsFrame): lineNumber = len(settingsList) settingsList.append({"transitionValue": "", "color": "#FFFFFF"}) settingsList[lineNumber]["transitionValue"] = tk.StringVar() settingsList[lineNumber]["transitionValue"].set(str(100*lineNumber)) removeButton = tk.Button(dpsFrame, text="X", command=lambda:self.removeLine(lineNumber, settingsList, dpsFrame)) font = tkFont.Font(font=removeButton['font']) font.config(weight='bold') removeButton['font'] = font removeButton.grid(row=lineNumber, column="0") lineLabel = tk.Label(dpsFrame, text="Threshold when the line changes color:") lineLabel.grid(row=lineNumber, column="1") initialThreshold = tk.Entry(dpsFrame, textvariable=settingsList[lineNumber]["transitionValue"], width=10) initialThreshold.grid(row=lineNumber, column="2") initialLabel = tk.Label(dpsFrame, text="Color:") initialLabel.grid(row=lineNumber, column="3") colorButton = tk.Button(dpsFrame, text=" ", command=lambda:self.colorWindow(settingsList[lineNumber], colorButton), bg=settingsList[lineNumber]["color"]) colorButton.grid(row=lineNumber, column="4")
def createhand(self): # create text display self.textid = self.create_text(self.centrex, self.centrey - 3*self.blobrad, fill = 'red', font = tkf.Font(size = -int(2*self.majortick))) # create moving and changeable bits self.handid = self.create_line(self.centrex,self.centrey, self.centrex - self.handlen,self.centrey, width = 2*self.linewidth, fill = 'red') self.blobid = self.create_oval(self.centrex - self.blobrad, self.centrey - self.blobrad, self.centrex + self.blobrad, self.centrey + self.blobrad, outline = 'black', fill = 'black')
def __init__(self, master, label=None): """label is function for DrawTree that takes node and returns int.""" self.master = master self.frame = Toplevel(width=960, height=512) self.canvas = Canvas(self.frame, width=960, height=512) # Initialize appropriate fonts to use DrawTree.smallFont = Font(family='Times', size='14') DrawTree.largeFont = Font(family='Times', size='24') self.frame.title("QuadTree Visualization") self.canvas.pack() self.label = label # React to window closure events self.frame.protocol("WM_DELETE_WINDOW", self.closed) self.done = False
def initialize_window(self): """ Initialize the window of the chat application. """ self.master.title("Chappie") self.master.columnconfigure(0, weight=1) self.master.columnconfigure(1, weight=4) self.master.columnconfigure(2, weight=1) self.master.configure(bg="gray20") self.master.resizable(0,0) # Custom Fonts self.header_font = tkFont.Font(family="Verdana", size=14, weight="bold") self.default_font = tkFont.Font(family="Verdana", size=10) # Set size of window and central start location w = 900 h = 460 sw = self.master.winfo_screenwidth() sh = self.master.winfo_screenheight() x = (sw/2) - (w/2) y = (sh/2) - (h/2) self.master.geometry('%dx%d+%d+%d' % (w, h, x, y))
def __init__(self, master, width=0, height=0, family=None, size=None,*args, **kwargs): Frame.__init__(self, master, width = width, height= height) self.pack_propagate(False) self._min_width = width self._min_height = height self._textarea = Text(self, *args, **kwargs) self._textarea.pack(expand=True, fill='both') if family != None and size != None: self._font = tkFont.Font(family=family,size=size) else: self._font = tkFont.Font(family=self._textarea.cget("font")) self._textarea.config(font=self._font) # I want to insert a tag just in front of the class tag # It's not necesseary to guive to this tag extra priority including it at the beginning # For this reason I am making this search self._autoresize_text_tag = "autoresize_text_"+str(id(self)) list_of_bind_tags = list(self._textarea.bindtags()) list_of_bind_tags.insert(list_of_bind_tags.index('Text'), self._autoresize_text_tag) self._textarea.bindtags(tuple(list_of_bind_tags)) self._textarea.bind_class(self._autoresize_text_tag, "<KeyPress>",self._on_keypress)
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 body(self, master): style = font.Font(self, size=TITLE_SIZE) self.status = Label(master, text=self.message, font=style) self.status.grid(sticky=NSEW, padx=TITLE_SIZE, pady=TITLE_SIZE) return self.status
def body(self, master): title = font.Font(self, size=TITLE_SIZE) legend = font.Font(self, weight='bold') # Create display variables. self.category = StringVar(master) self.question = StringVar(master) self.answer = StringVar(master) self.right = StringVar(master) # Create form labels. self.c_label = Label(master, textvariable=self.category, font=title) self.q_label = Label(master, textvariable=self.question) self.you_answered = Label(master, text='You answered:', font=legend) self.a_label = Label(master, textvariable=self.answer) self.right_answer = Label(master, text='Right answer:', font=legend) self.r_label = Label(master, textvariable=self.right) # Create control buttons. options = {'text': '< < <', 'width': TEXT_WIDTH // 2, 'command': self.go_back} self.back = Button(master, **options) options = {'text': '> > >', 'width': TEXT_WIDTH // 2, 'command': self.go_next} self.next = Button(master, **options) # Display the body. options = {'sticky': NSEW, 'padx': 5, 'pady': 5} self.c_label.grid(row=0, column=0, columnspan=2, **options) self.q_label.grid(row=1, column=0, columnspan=2, **options) self.you_answered.grid(row=2, column=0, **options) self.a_label.grid(row=2, column=1, **options) self.right_answer.grid(row=3, column=0, **options) self.r_label.grid(row=3, column=1, **options) self.back.grid(row=4, column=0, **options) self.next.grid(row=4, column=1, **options) # Update the labels. self.update()
def body(self, master): title = font.Font(self, size=TITLE_SIZE) legend = {'anchor': W, 'justify': LEFT, 'font': font.Font(self, weight='bold')} # Create all labels. text = 'Cumulative score for\nprevious {}:'.format(self.level) self.explanation = Label(master, text=text, font=title) self.ruler_one = Label(master, text=(self.RULE * TEXT_WIDTH)) self.answers_right = Label(master, text='Answers right:', **legend) self.display_right = Label(master, text=str(self.right)) self.answers_wrong = Label(master, text='Answers wrong:', **legend) self.display_wrong = Label(master, text=str(self.wrong)) self.percent = Label(master, text='Percentage correct:', **legend) percentage = str(int(100 * self.right / self.total + 0.5)) + '%' self.display = Label(master, text=percentage) self.ruler_two = Label(master, text=(self.RULE * TEXT_WIDTH)) # Display the results. options = {'sticky': NSEW, 'padx': 5, 'pady': 5} self.explanation.grid(row=0, column=0, columnspan=2, **options) self.ruler_one.grid(row=1, column=0, columnspan=2, **options) self.answers_right.grid(row=2, column=0, **options) self.display_right.grid(row=2, column=1, **options) self.answers_wrong.grid(row=3, column=0, **options) self.display_wrong.grid(row=3, column=1, **options) self.percent.grid(row=4, column=0, **options) self.display.grid(row=4, column=1, **options) self.ruler_two.grid(row=5, column=0, columnspan=2, **options)
def setUpClass(cls): AbstractTkTest.setUpClass.__func__(cls) try: cls.font = font.Font(root=cls.root, name=fontname, exists=True) except tkinter.TclError: cls.font = font.Font(root=cls.root, name=fontname, exists=False)
def test_eq(self): font1 = font.Font(root=self.root, name=fontname, exists=True) font2 = font.Font(root=self.root, name=fontname, exists=True) self.assertIsNot(font1, font2) self.assertEqual(font1, font2) self.assertNotEqual(font1, font1.copy()) self.assertNotEqual(font1, 0)
def _load_browse_data(self): self.data = self._get_current_browse_list() self.pathLabel['text'] = "> " + self.dir_browser.get_friendly_path_name(" + ") self.tree.delete(*self.tree.get_children()) # add data to the tree self.tree_index = dict() for idx in range(len(self.dataCols)): self.tree.column(self.dataCols[idx], width=10) for item in self.data: index = self.tree.insert('', 'end', values=item[1:]) self.tree_index[index] = item for idx in range(len(self.dataCols)): iwidth = Font().measure(item[idx + 1]) + 10 if self.tree.column(self.dataCols[idx], 'width') < iwidth: self.tree.column(self.dataCols[idx], width=iwidth)
def Title(): # Title Setting Start. logoBack = Label(root, bg = "white") logoBack.place(width = 1000, height = 85) logoLine1 = Label(root, bg="black") logoLine1.place(x=180, y=20, width=170, height=10) logoLine2 = Label(root, bg="black") logoLine2.place(x=180, y=40, width=170, height=10) logoLine3 = Label(root, bg="black") logoLine3.place(x=180, y=60, width=170, height=10) logoLine4 = Label(root, bg="black") logoLine4.place(x=700, y=20, width=170, height=10) logoLine5 = Label(root, bg="black") logoLine5.place(x=700, y=40, width=170, height=10) logoLine6 = Label(root, bg="black") logoLine6.place(x=700, y=60, width=170, height=10) logo = Label(root, image = logoImage, bg = 'white') logo.place(x=0, y=0) star = Label(root, image = starImage, bg = 'white') star.place(x=890, y=0) fontemp = font.Font(root, size = 40, weight = 'bold', slant = 'italic') title = Label(root, font = fontemp, text="BOX OFFICE", bg = "white") title.place(x=360, y=10) # Title Setting End. # BoxOffice==================================
def BoxOfficeMenu(): global list_boxOffice, m1_ListBox, m2_ListBox, m3_ListBox, m4_ListBox, m5_ListBox global dic_thumbnail, image bgLabel = Label(bo_Frame, width=600, height=600, bg='white') bgLabel.place(x=0, y=0) list_boxOffice = getXML(yesterday, 0, 0) init_dateInputLabel() init_dateSearchButton() init_SortingButton() fontemp = font.Font(bo_Frame, size=12, weight='bold') # BoxOffice Tab Setting Start. m1_ListBox = Listbox(bo_Frame, font=fontemp, width=37, height=11, borderwidth=2, relief='ridge') m1_ListBox.place(x=80, y=75) m2_ListBox = Listbox(bo_Frame, font=fontemp, width=11, height=11, borderwidth=2, relief='ridge') m2_ListBox.place(x=0, y=400) m3_ListBox = Listbox(bo_Frame, font=fontemp, width=14, height=11, borderwidth=2, relief='ridge') m3_ListBox.place(x=105, y=400) m4_ListBox = Listbox(bo_Frame, font=fontemp, width=12, height=11, borderwidth=2, relief='ridge') m4_ListBox.place(x=238, y=400) m5_ListBox = Listbox(bo_Frame, font=fontemp, width=16, height=11, borderwidth=2, relief='ridge') m5_ListBox.place(x=353, y=400) dateText = Label(bo_Frame, font=fontemp, bg="grey", fg="black", text="BOX OFFICE ??") dateText.place(x=180, y=15) m1_ListBox.bind('<<ListboxSelect>>', listBox_Event) # BoxOffice Tab Setting End.
def init_dateInputLabel(): global InputLabel fontemp = font.Font(bo_Frame, size=12, weight='bold') dateLabel = Label(bo_Frame, font=fontemp, text="?? ??\n(YYYYMMDD)", bg='grey') dateLabel.place(x=405, y = 13) InputLabel = Entry(bo_Frame, font=fontemp, width=14, borderwidth=3, relief='ridge') InputLabel.place(x=520, y=20)
def init_dateSearchButton(): fontemp = font.Font(bo_Frame, size=12, weight='bold') sButton = Button(bo_Frame, font=fontemp, text = "??", command=lambda: searchButtonAction(0)) sButton.place(x=670, y=17)
def init_searchInputLabel(): global Input_search fontemp = font.Font(sc_Frame, size=12, weight='bold') searchLabel = Label(sc_Frame, font=fontemp, text="?? ?? ??", bg = 'grey') searchLabel.place(x=65, y=10) Input_search = Entry(sc_Frame, font=fontemp, width=20, borderwidth=3, relief='ridge') Input_search.place(x=20, y=40) fontemp = font.Font(sc_Frame, size=12, weight='bold') sButton = Button(sc_Frame, font=fontemp, text="??", command=lambda : get_search()) sButton.place(x=220, y=37)
def get_search(): global list_movieData, s1_ListBox q = Input_search.get() fontemp = font.Font(sc_Frame, size=12, weight='bold') list_movieData = getXML(q, 1, 0) s1_ListBox.delete(0,END) rank = 0; for i in list_movieData: rank += 1 s1_ListBox.insert(rank - 1, "- {0}\n".format(i['movieNm']))
def get_movieinfo(q): global list_movieData, dic_detailData, s2_ListBox fontemp = font.Font(sc_Frame, size=12, weight='bold') dic_detailData = getXML(q, 2, 0) s2_ListBox.delete(0, END) s2_ListBox.insert(END, "??: {0}\n".format(dic_detailData['movieNm'])) s2_ListBox.insert(END, "?? ??: {0}\n".format(dic_detailData['movieNmEn'])) s2_ListBox.insert(END, "????: {0}?\n".format(dic_detailData['showTm'])) s2_ListBox.insert(END, "???: {0}\n".format(dic_detailData['openDt'])) s2_ListBox.insert(END, "????: {0}\n".format(dic_detailData['nationNm'])) s2_ListBox.insert(END, "??: {0}\n".format(dic_detailData['genreNm'])) s2_ListBox.insert(END, "???: {0}\n".format(dic_detailData['dirNm'])) s2_ListBox.insert(END, "????: {0}\n".format(dic_detailData['watchGradeNm']))
def label_size(self, label): """Calculate label size""" font_family, font_size = self.font font = Font(family=font_family, size=font_size) width = 0 lines = 0 for line in label.split('\n'): width = max(width, font.measure(line)) lines += 1 xscale = turtle.getscreen().xscale yscale = turtle.getscreen().yscale return width / xscale, font.metrics('linespace') * lines / yscale
def label_pos(self, pos, label=None, horizontal=False): """Calculate label start position (top-right if vertical, top-center if horizontal)""" xscale = turtle.getscreen().xscale yscale = turtle.getscreen().yscale font_family, font_size = self.font font = Font(family=font_family, size=font_size) line_height = font.metrics('linespace') / yscale height = (label.count('\n') + 1) * line_height return -8 / xscale if horizontal else pos, \ pos - 0.5 * height if horizontal else -height - 6 / yscale
def test_font_eq(self): fontname = "TkDefaultFont" try: f = font.Font(name=fontname, exists=True) except tkinter._tkinter.TclError: f = font.Font(name=fontname, exists=False) font1 = font.nametofont(fontname) font2 = font.nametofont(fontname) self.assertIsNot(font1, font2) self.assertEqual(font1, font2) self.assertNotEqual(font1, font1.copy()) self.assertNotEqual(font1, 0)
def change_size(self,event): tk.customFont = font.Font(family = "Helvetica",size = 12,weight = "normal",slant = "roman",underline =0) size = tk.customFont["size"] tk.customFont.configure(size =self.list_size.get(self.list_size.curselection())) self.st.config(font = tk.customFont) self.size_count = 1 pass
def change_font(self,event): tk.customFont = font.Font(family = "Helvetica",size = 12,weight = "normal",slant = "roman",underline =0) family = tk.customFont["family"] tk.customFont.configure(family =self.list_font.get(self.list_font.curselection())) self.st.config(font = tk.customFont) self.font_count = 1 pass
def change_shape(self,event): tk.customFont = font.Font(family = "Helvetica",size = 12,weight = "normal",slant = "roman",underline =0) slant = tk.customFont["slant"] tk.customFont.configure(slant =self.list_shape.get(self.list_shape.curselection())) self.st.config(font = tk.customFont) self.shape_count =1 pass
def change_weight(self,event): tk.customFont = font.Font(family = "Helvetica",size = 12,weight = "normal",slant = "roman",underline =0) weight = tk.customFont["weight"] tk.customFont.configure(weight =self.list_weight.get(self.list_weight.curselection())) self.st.config(font = tk.customFont) self.shape_count =1
def __init__(self, drs, size_canvas=True, canvas=None): """ :param drs: ``DrtExpression``, 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 __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)