本文整理汇总了Python中tkinter.font.Font.configure方法的典型用法代码示例。如果您正苦于以下问题:Python Font.configure方法的具体用法?Python Font.configure怎么用?Python Font.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.font.Font
的用法示例。
在下文中一共展示了Font.configure方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adjust_fonts
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def adjust_fonts(self, event):
new_font = Font(**self.fonts['normal'].configure())
size = orig_size = new_font['size']
desired_total_height = event.height
orig_row_height = new_font.metrics('linespace')
orig_row_height += self.LS_EXTRA
orig_total_height = self.N_ROWS * orig_row_height
if orig_total_height < desired_total_height:
a, compfname, final_neg_adjust = 1, '__gt__', True
elif orig_total_height > desired_total_height:
a, compfname, final_neg_adjust = -1, '__lt__', False
else:
return
prev_total_height = orig_total_height
while True:
if a < 0 and size <= self.MIN_FONT_SIZE:
size = self.MIN_FONT_SIZE
break
size += a
new_font.configure(size=size)
new_row_height = new_font.metrics('linespace')
new_row_height += self.LS_EXTRA
new_total_height = self.N_ROWS * new_row_height
if new_total_height == prev_total_height:
size -= a
break
compf = getattr(new_total_height, compfname)
if compf(desired_total_height):
if final_neg_adjust and size > self.MIN_FONT_SIZE:
size -= a
break
prev_total_height = new_total_height
if size != orig_size:
self.fonts['normal'].configure(size=size)
self.fonts['bold'].configure(size=size)
示例2: overstrike
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def overstrike(self, *args):
"""Toggles overstrike for selected text."""
try:
current_tags = self.text.tag_names("sel.first")
if "overstrike" in current_tags:
self.text.tag_remove("overstrike", "sel.first", "sel.last")
else:
self.text.tag_add("overstrike", "sel.first", "sel.last")
overstrike_font = Font(self.text, self.text.cget("font"))
overstrike_font.configure(overstrike=1)
self.text.tag_configure("overstrike", font=overstrike_font)
except TclError:
pass
示例3: underline
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def underline(self, *args):
"""Toggles underline for selected text."""
try:
current_tags = self.text.tag_names("sel.first")
if "underline" in current_tags:
self.text.tag_remove("underline", "sel.first", "sel.last")
else:
self.text.tag_add("underline", "sel.first", "sel.last")
underline_font = Font(self.text, self.text.cget("font"))
underline_font.configure(underline=1)
self.text.tag_configure("underline", font=underline_font)
except TclError:
pass
示例4: italic
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def italic(self, *args):
"""Toggles italic for selected text."""
try:
current_tags = self.text.tag_names("sel.first")
if "italic" in current_tags:
self.text.tag_remove("italic", "sel.first", "sel.last")
else:
self.text.tag_add("italic", "sel.first", "sel.last")
italic_font = Font(self.text, self.text.cget("font"))
italic_font.configure(slant="italic")
self.text.tag_configure("italic", font=italic_font)
except TclError:
pass
示例5: bold
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def bold(self, *args):
"""Toggles bold for selected text."""
try:
current_tags = self.text.tag_names("sel.first")
if "bold" in current_tags:
self.text.tag_remove("bold", "sel.first", "sel.last")
else:
self.text.tag_add("bold", "sel.first", "sel.last")
bold_font = Font(self.text, self.text.cget("font"))
bold_font.configure(weight="bold")
self.text.tag_configure("bold", font=bold_font)
except TclError:
pass
示例6: __init__
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def __init__(self, master, client, queue, send_command):
super(ClientUI, self).__init__()
self.client = client
self.queue = queue
self.send_command = send_command
self.master = master
self.plugin_manager = PluginManager(self.send_command_with_prefs, self.echo)
self.interrupt_input = False
self.interrupt_buffer = deque()
self.input_buffer = []
self.input_cursor = 0
self.list_depth = 0
self.MAP_OFFSET = 60
menu_bar = tk.Menu(master)
self.menu_file = tk.Menu(menu_bar, tearoff=0)
self.menu_file.add_command(label="Preferences", command=self.show_preferences)
self.menu_file.add_command(label="Disconnect", command=self.client.shutdown)
self.menu_file.add_command(label="Quit", command=self.client.quit)
menu_bar.add_cascade(label="Client", menu=self.menu_file)
self.create_plugin_menu(menu_bar)
self.master.config(menu=menu_bar)
self.master.grid()
tk.Grid.rowconfigure(self.master, 0, weight=1)
tk.Grid.columnconfigure(self.master, 0, weight=1)
self.status = dict()
self.create_widgets()
self.side_bar = master.children['side_bar']
self.output_panel = master.children['output_frame'].children['output']
self.output_panel.configure(state="normal")
self.output_panel.bind('<Key>', lambda e: 'break')
self.input = master.children['input']
self.context_menu = master.children['context_menu']
self.char_width = Font(self.output_panel, self.output_panel.cget("font")).measure('0')
self.line_length = self.calc_line_length(self.output_panel.cget("width"))
italic_font = Font(self.output_panel, self.output_panel.cget("font"))
italic_font.configure(slant='italic')
self.output_panel.tag_configure("italic", font=italic_font)
bold_font = Font(self.output_panel, self.output_panel.cget("font"))
bold_font.configure(weight='bold')
self.output_panel.tag_configure('bold', font=bold_font)
self.output_panel.tag_configure("center", justify=tk.CENTER)
示例7: __init__
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def __init__(self, master, client, queue, send_command):
super(ClientUI, self).__init__()
self.client = client
self.queue = queue
self.send_command = send_command
self.master = master
self.interrupt_input = False
self.interrupt_buffer = deque()
self.input_buffer = []
self.input_cursor = 0
self.list_depth = 0
menu_bar = tk.Menu(master)
self.menu_file = tk.Menu(menu_bar, tearoff=0)
self.menu_file.add_command(label="Preferences", command=self.show_preferences)
self.menu_file.add_command(label="Disconnect", command=self.client.shutdown)
self.menu_file.add_command(label="Quit", command=self.client.quit)
menu_bar.add_cascade(label="Client", menu=self.menu_file)
self.master.config(menu=menu_bar)
self.master.grid()
tk.Grid.rowconfigure(self.master, 0, weight=1)
tk.Grid.columnconfigure(self.master, 0, weight=1)
self.create_widgets()
# pprint(vars(master))
self.side_bar = master.children['side_bar']
self.output_panel = master.children['output']
self.input = master.children['input']
self.char_width = Font(self.output_panel, self.output_panel.cget("font")).measure('0')
self.line_length = self.calc_line_length(self.output_panel.cget("width"))
italic_font = Font(self.output_panel, self.output_panel.cget("font"))
italic_font.configure(slant='italic')
self.output_panel.tag_configure("italic", font=italic_font)
bold_font = Font(self.output_panel, self.output_panel.cget("font"))
bold_font.configure(weight='bold')
self.output_panel.tag_configure('bold', font=bold_font)
self.output_panel.tag_configure("center", justify=tk.CENTER)
示例8: __init__
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def __init__(self, master):
BaseDiablog.__init__(self, master, "Preferences", exit_on_esc=True)
self.startup_check = Config.config["startup_check"]
self.general_label = ttk.Label(self.body,
text="General")
font = Font(self.general_label, self.general_label.cget("font"))
font.configure(underline=True)
self.general_label.configure(font=font)
self.config_frame = ttk.Frame(self)
self.startup_check_checkbtn = ttk.Checkbutton(self.config_frame,
text="Check for update at launch",
variable=PreferencesDialog.startup_check.raw_klass(self),
command=self._startup_check_clicked)
self.buttons_frame = ttk.Frame(self)
self.close_button = ttk.Button(self.buttons_frame,
text="Close",
command=self.destroy)
options = dict(padx=5, pady=5)
self.general_label.pack(side=LEFT, **options)
self.config_frame.pack(fill=BOTH, expand=True, **options)
self.startup_check_checkbtn.pack(side=LEFT, **options)
self.buttons_frame.pack(side=BOTTOM, fill=BOTH, expand=True, **options)
self.close_button.pack(side=RIGHT, expand=False)
示例9: DrtGlueDemo
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
class DrtGlueDemo(object):
def __init__(self, examples):
# Set up the main window.
self._top = Tk()
self._top.title("DRT Glue Demo")
# Set up key bindings.
self._init_bindings()
# Initialize the fonts.self._error = None
self._init_fonts(self._top)
self._examples = examples
self._readingCache = [None for example in examples]
# The user can hide the grammar.
self._show_grammar = IntVar(self._top)
self._show_grammar.set(1)
# Set the data to None
self._curExample = -1
self._readings = []
self._drs = None
self._drsWidget = None
self._error = None
self._init_glue()
# Create the basic frames.
self._init_menubar(self._top)
self._init_buttons(self._top)
self._init_exampleListbox(self._top)
self._init_readingListbox(self._top)
self._init_canvas(self._top)
# Resize callback
self._canvas.bind("<Configure>", self._configure)
#########################################
## Initialization Helpers
#########################################
def _init_glue(self):
tagger = RegexpTagger(
[
("^(David|Mary|John)$", "NNP"),
("^(walks|sees|eats|chases|believes|gives|sleeps|chases|persuades|tries|seems|leaves)$", "VB"),
("^(go|order|vanish|find|approach)$", "VB"),
("^(a)$", "ex_quant"),
("^(every)$", "univ_quant"),
("^(sandwich|man|dog|pizza|unicorn|cat|senator)$", "NN"),
("^(big|gray|former)$", "JJ"),
("^(him|himself)$", "PRP"),
]
)
depparser = MaltParser(tagger=tagger)
self._glue = DrtGlue(depparser=depparser, remove_duplicates=False)
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_exampleListbox(self, parent):
self._exampleFrame = listframe = Frame(parent)
self._exampleFrame.pack(fill="both", side="left", padx=2)
self._exampleList_label = Label(self._exampleFrame, font=self._boldfont, text="Examples")
self._exampleList_label.pack()
self._exampleList = Listbox(
self._exampleFrame,
selectmode="single",
relief="groove",
background="white",
foreground="#909090",
font=self._font,
selectforeground="#004040",
selectbackground="#c0f0c0",
)
self._exampleList.pack(side="right", fill="both", expand=1)
for example in self._examples:
self._exampleList.insert("end", (" %s" % example))
self._exampleList.config(height=min(len(self._examples), 25), width=40)
# Add a scrollbar if there are more than 25 examples.
if len(self._examples) > 25:
#.........这里部分代码省略.........
示例10: MainApplication
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
class MainApplication(tk.Tk):
"""main application window
Attributes:
all_servers (list): returns list of all servers
customFont (TYPE): defined two types of fonts for mac/win compatibility
entry (entry field): enter number of the server that failed to render
file_contents (list): the contents of the Backburner job file
ip_address (txt): check if the render manager is available and fill it's ip address
job_name (txt): Backburner job name
L1 (UI label): label
PRIORITY (txt): set priority for new Backburner job
RENDER_MANAGER (txt): render manager name
run_button (button): run program to create .bat-render file
SCENE_LOOKUP (txt): path to the folder with .max files
selected_server (txt): failed server name you have chosen
server_frames_list (list): list of frames assigned to failed server to be re-rendered
servers (list): list of servers in Backburner job
text (txt): console text field
the_csv_file (file): Backburner job exported file
var (int): 1 - to call 'open result' function; 0 - to pass
VERSION (txt): 3DsMax version
"""
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.geometry('+300+100')
self.title('pyBurner')
self.configure(bg=BGCOLOR)
if os_name == 'Darwin':
self.customFont = Font(family="Lucida Console", size=10)
txt_area = [18, 53]
elif os_name == 'Windows':
txt_area = [18, 48]
self.customFont = nametofont("TkDefaultFont")
self.customFont.configure(size=9)
# text area
frame1 = tk.Frame(self)
frame1.configure(background=BGCOLOR)
frame1.grid(row=0, column=0, columnspan=2, sticky='w')
scrollbar = tk.Scrollbar(frame1)
self.text = MyTextSettings(
frame1, height=txt_area[0], width=txt_area[1], yscrollcommand=scrollbar.set
)
self.text.pack(padx=(4, 0), side=tk.LEFT, expand=True)
scrollbar.configure(command=self.text.yview)
scrollbar.pack(side=tk.LEFT, fill=tk.Y, expand=False)
# labels area
l_frame = tk.Frame(self)
l_frame.config(background=BGCOLOR)
l_frame.grid(row=1, column=0, pady=5)
self.L1 = MyLabel(l_frame, font=self.customFont)
self.L1.pack()
self.var = tk.IntVar()
checkbutton1 = tk.Checkbutton(
l_frame,
font=self.customFont,
background=BGCOLOR,
activebackground=BGCOLOR,
variable=self.var,
)
checkbutton1.pack(side=tk.LEFT)
L2 = MyLabel(l_frame, bg="red", text="open result", font=self.customFont)
L2.pack(side=tk.LEFT)
# buttons area
b_frame = tk.Frame(self)
b_frame.config(bg=BGCOLOR)
b_frame.grid(row=1, column=1, padx=(0, 20), sticky='e')
submit_button = tk.Button(
b_frame, text='submit', command=self.get_server_entry, font=self.customFont
)
submit_button.grid(row=1, column=3, padx=(0, 3), sticky='w')
submit_button.configure(highlightbackground=BGCOLOR)
self.bind('<Return>', self.get_server_entry)
self.run_button = tk.Button(
b_frame, text='run', command=self.run_app, font=self.customFont
)
self.run_button.configure(highlightbackground=BGCOLOR)
self.run_button.grid(row=1, column=4, padx=(0, 3))
self.bind('<Control-r>', self.run_app)
reset_button = tk.Button(
b_frame, text='reset', command=self.cleanup, font=self.customFont
)
reset_button.config(highlightbackground=BGCOLOR)
reset_button.grid(row=1, column=5, sticky='we')
self.showall_button = tk.Button(
b_frame, text='all jobs', command=self.show_all, state=tk.DISABLED
)
self.showall_button.configure(highlightbackground=BGCOLOR, font=self.customFont)
self.showall_button.grid(row=2, column=3, sticky='w')
close_button = tk.Button(
b_frame, text='close', command=self.quit_app, font=self.customFont
)
close_button.configure(highlightbackground=BGCOLOR)
close_button.grid(row=2, column=4, columnspan=2, sticky='we')
self.entry = tk.Entry(b_frame, width=6, font=self.customFont)
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import configure [as 别名]
def __init__(self):
"""Initialize widgets, methods."""
tkinter.Tk.__init__(self)
self.grid()
fontoptions = families(self)
font = Font(family="Verdana", size=10)
menubar = tkinter.Menu(self)
fileMenu = tkinter.Menu(menubar, tearoff=0)
editMenu = tkinter.Menu(menubar, tearoff=0)
fsubmenu = tkinter.Menu(editMenu, tearoff=0)
ssubmenu = tkinter.Menu(editMenu, tearoff=0)
# adds fonts to the font submenu and associates lambda functions
for option in fontoptions:
fsubmenu.add_command(label=option, command = lambda: font.configure(family=option))
# adds values to the size submenu and associates lambda functions
for value in range(1,31):
ssubmenu.add_command(label=str(value), command = lambda: font.configure(size=value))
# adds commands to the menus
menubar.add_cascade(label="File",underline=0, menu=fileMenu)
menubar.add_cascade(label="Edit",underline=0, menu=editMenu)
fileMenu.add_command(label="New", underline=1,
command=self.new, accelerator="Ctrl+N")
fileMenu.add_command(label="Open", command=self.open, accelerator="Ctrl+O")
fileMenu.add_command(label="Save", command=self.save, accelerator="Ctrl+S")
fileMenu.add_command(label="Exit", underline=1,
command=exit, accelerator="Ctrl+Q")
editMenu.add_command(label="Copy", command=self.copy, accelerator="Ctrl+C")
editMenu.add_command(label="Cut", command=self.cut, accelerator="Ctrl+X")
editMenu.add_command(label="Paste", command=self.paste, accelerator="Ctrl+V")
editMenu.add_cascade(label="Font", underline=0, menu=fsubmenu)
editMenu.add_cascade(label="Size", underline=0, menu=ssubmenu)
editMenu.add_command(label="Color", command=self.color)
editMenu.add_command(label="Bold", command=self.bold, accelerator="Ctrl+B")
editMenu.add_command(label="Italic", command=self.italic, accelerator="Ctrl+I")
editMenu.add_command(label="Underline", command=self.underline, accelerator="Ctrl+U")
editMenu.add_command(label="Overstrike", command=self.overstrike, accelerator="Ctrl+T")
editMenu.add_command(label="Undo", command=self.undo, accelerator="Ctrl+Z")
editMenu.add_command(label="Redo", command=self.redo, accelerator="Ctrl+Y")
self.config(menu=menubar)
"""Accelerator bindings. The cut, copy, and paste functions are not
bound to keyboard shortcuts because Windows already binds them, so if
Tkinter bound them as well whenever you typed ctrl+v the text would be
pasted twice."""
self.bind_all("<Control-n>", self.new)
self.bind_all("<Control-o>", self.open)
self.bind_all("<Control-s>", self.save)
self.bind_all("<Control-q>", self.exit)
self.bind_all("<Control-b>", self.bold)
self.bind_all("<Control-i>", self.italic)
self.bind_all("<Control-u>", self.underline)
self.bind_all("<Control-T>", self.overstrike)
self.bind_all("<Control-z>", self.undo)
self.bind_all("<Control-y>", self.redo)
self.text = ScrolledText(self, state='normal', height=30, wrap='word', font = font, pady=2, padx=3, undo=True)
self.text.grid(column=0, row=0, sticky='NSEW')
# Frame configuration
self.grid_columnconfigure(0, weight=1)
self.resizable(True, True)