本文整理汇总了Python中tkinter.CENTER属性的典型用法代码示例。如果您正苦于以下问题:Python tkinter.CENTER属性的具体用法?Python tkinter.CENTER怎么用?Python tkinter.CENTER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类tkinter
的用法示例。
在下文中一共展示了tkinter.CENTER属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: popup
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def popup(self, window, title, image, text, button_text, end_command=None):
popup = tk.Toplevel(window)
popup.resizable(False, False)
if MAIN_ICON != None:
if os.path.splitext(MAIN_ICON)[1].lower() == ".gif":
dummy = None
#popup.call('wm', 'iconphoto', popup._w, tk.PhotoImage(file=MAIN_ICON))
else:
popup.iconbitmap(MAIN_ICON)
popup.wm_title(title)
popup.tkraise(window)
def run_end():
popup.destroy()
if end_command != None:
end_command()
picture_label = tk.Label(popup, image=image)
picture_label.photo = image
picture_label.grid(column=0, row=0, rowspan=2, padx=10, pady=10)
tk.Label(popup, text=text, justify=tk.CENTER).grid(column=1, row=0, padx=10, pady=10)
tk.Button(popup, text=button_text, command=run_end).grid(column=1, row=1, padx=10, pady=10)
popup.wait_visibility()
popup.grab_set()
popup.wait_window()
示例2: _draw_node
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def _draw_node(self, coord, data_node):
"""Create a token for the data_node at the given coordinater"""
(x,y) = coord
data = self.dataG.node[data_node]
# Apply filter to node to make sure we should draw it
for filter_lambda in self._node_filters:
try:
draw_flag = eval(filter_lambda, {'u':data_node, 'd':data})
except Exception as e:
self._show_filter_error(filter_lambda, e)
return
# Filters are applied as an AND (ie, all must be true)
# So if one is false, exit
if draw_flag == False:
return
# Create token and draw node
token = self._NodeTokenClass(self, data, data_node)
id = self.create_window(x, y, window=token, anchor=tk.CENTER,
tags='node')
self.dispG.add_node(id, {'dataG_id': data_node,
'token_id': id, 'token': token})
return id
示例3: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def __init__(self, master): # constructor method
# define list of label texts
self.greet_list = ('Hello, World! This is python GUI.', \
'Hello, This is Python GUI. Sadly, I was made to say Hello only. I will love to say so much more.')
# creat label as a child of root window with some text.
self.label = ttk.Label(master, text = self.greet_list[0])
self.btn = ttk.Button(master, text = 'Greet Again', command = self.handle_text) # create a button
# store image in the label obj to keep it in the scope as
# long as label is displayed and to avoid getting the image getting garbage collected
imgpath = 'simple_gif.gif' # path of the image
self.label.img = tk.PhotoImage(file = imgpath) # read_image :: saving image within label_object to prevent its garbage collection
self.label.config(image = self.label.img) # display image in label widget
self.label.config(compound = 'left') # to display image in left of text
self.label.pack() # pack label to the window with pack() geometry method of Label
self.btn.pack()
self.label.config(wraplength = 200) # specify wraplength of text in label
self.label.config(justify = tk.CENTER) # justify text in label to (CENTER, RIGHT or LEFT)
self.label.config(foreground = 'blue', background = 'yellow') # insert font color (foreground) and background color
self.label.config(font = ('Times', 10, 'bold')) # font = (font_name, font_size, font_type)
示例4: create_statusbar
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def create_statusbar(self):
statusBar = ttk.Frame(self.master)
statusLabel = ttk.Label(statusBar, textvariable=self.statusText)
statusLabel.grid(column=0, row=0, sticky=(tk.W, tk.E))
self.modifiedLabel = ttk.Label(statusBar, relief=tk.SUNKEN,
anchor=tk.CENTER)
self.modifiedLabel.grid(column=1, row=0, pady=2, padx=1)
TkUtil.Tooltip.Tooltip(self.modifiedLabel,
text="MOD if the text has unsaved changes")
self.positionLabel = ttk.Label(statusBar, relief=tk.SUNKEN,
anchor=tk.CENTER)
self.positionLabel.grid(column=2, row=0, sticky=(tk.W, tk.E),
pady=2, padx=1)
TkUtil.Tooltip.Tooltip(self.positionLabel,
text="Current line and column position")
ttk.Sizegrip(statusBar).grid(row=0, column=4, sticky=(tk.S, tk.E))
statusBar.columnconfigure(0, weight=1)
statusBar.grid(row=2, column=0, columnspan=3, sticky=(tk.W, tk.E))
self.set_status_text("Start typing to create a new document or "
"click File→Open")
示例5: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def __init__(self, parent, **kwargs):
super().__init__(parent,
bd=7,
bg="white smoke",
**kwargs)
tk.Frame(self,width=340,
height=340).grid(sticky="nswe")
self.info_label = tk.Message(self,
font=self.font,
anchor=tk.CENTER,
bg="white smoke",
width=1000)
self.comments = tk.Label(self,
justify=tk.LEFT,
font=self.comment_font,
width=20,
bg="white smoke")
self.info_label.grid(row=0, column=0, sticky="nswe")
self.comments.grid(row=1, column=0, sticky="nse")
self.ticket = None
示例6: create_header
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def create_header(self):
left_arrow = {'children': [('Button.leftarrow', None)]}
right_arrow = {'children': [('Button.rightarrow', None)]}
style = ttk.Style(self)
style.layout('L.TButton', [('Button.focus', left_arrow)])
style.layout('R.TButton', [('Button.focus', right_arrow)])
hframe = ttk.Frame(self)
btn_left = ttk.Button(hframe, style='L.TButton',
command=lambda: self.move_month(-1))
btn_right = ttk.Button(hframe, style='R.TButton',
command=lambda: self.move_month(1))
label = ttk.Label(hframe, width=15, anchor='center')
hframe.pack(pady=5, anchor=tk.CENTER)
btn_left.grid(row=0, column=0)
label.grid(row=0, column=1, padx=12)
btn_right.grid(row=0, column=2)
return label
示例7: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def __init__(self):
super().__init__()
label_a = tk.Label(self, text="Label A", bg="yellow")
label_b = tk.Label(self, text="Label B", bg="orange")
label_c = tk.Label(self, text="Label C", bg="red")
label_d = tk.Label(self, text="Label D", bg="green")
label_e = tk.Label(self, text="Label E", bg="blue")
label_a.place(relwidth=0.25, relheight=0.25)
label_b.place(x=100, anchor=tk.N,
width=100, height=50)
label_c.place(relx=0.5, rely=0.5, anchor=tk.CENTER,
relwidth=0.5, relheight=0.5)
label_d.place(in_=label_c, anchor=tk.N + tk.W,
x=2, y=2, relx=0.5, rely=0.5,
relwidth=0.5, relheight=0.5)
label_e.place(x=200, y=200, anchor=tk.S + tk.E,
relwidth=0.25, relheight=0.25)
示例8: popup_choice
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def popup_choice(self, window, title, image, text, choices):
popup = tk.Toplevel(window)
popup.resizable(False, False)
if MAIN_ICON != None:
if os.path.splitext(MAIN_ICON)[1].lower() == ".gif":
dummy = None
#popup.call('wm', 'iconphoto', popup._w, tk.PhotoImage(file=MAIN_ICON))
else:
popup.iconbitmap(MAIN_ICON)
popup.wm_title(title)
popup.tkraise(window)
def run_end(func):
popup.destroy()
if func != None:
func()
picture_label = tk.Label(popup, image=image)
picture_label.photo = image
picture_label.grid(column=0, row=0, rowspan=2, padx=10, pady=10)
tk.Label(popup, text=text, justify=tk.CENTER).grid(column=1, row=0, columnspan=len(choices), padx=10, pady=10)
for idx, choice in enumerate(choices):
run_end_func = partial(run_end, choice[1])
tk.Button(popup, text=choice[0], command=run_end_func).grid(column=1 + idx, row=1, padx=10, pady=10)
popup.wait_visibility()
popup.grab_set()
popup.wait_window()
示例9: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def __init__(self, master, set_status_text=report, **kwargs):
super().__init__(master, **kwargs)
self.set_status_text = set_status_text
self.filename = None
for justify in (tk.LEFT, tk.CENTER, tk.RIGHT):
self.text.tag_configure(justify, justify=justify)
示例10: align
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def align(self, alignment):
for justify in {tk.LEFT, tk.CENTER, tk.RIGHT} - {alignment}:
self.text.tag_remove(justify, "1.0", tk.END)
self.text.tag_add(alignment, "1.0", tk.END)
示例11: create_view_menu
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def create_view_menu(self):
modifier = TkUtil.menu_modifier()
viewMenu = tk.Menu(self.menubar)
viewMenu.add_checkbutton(label=BOLD, underline=0,
image=self.menuImages[BOLD], compound=tk.LEFT,
variable=self.bold,
command=lambda: self.toggle_button(self.boldButton))
viewMenu.add_checkbutton(label=ITALIC, underline=0,
image=self.menuImages[ITALIC], compound=tk.LEFT,
variable=self.italic,
command=lambda: self.toggle_button(self.italicButton))
viewMenu.add_separator()
viewMenu.add_radiobutton(label=ALIGN_LEFT, underline=6,
image=self.menuImages[ALIGNLEFT], compound=tk.LEFT,
variable=self.alignment, value=tk.LEFT,
command=self.toggle_alignment)
viewMenu.add_radiobutton(label=ALIGN_CENTER, underline=6,
image=self.menuImages[ALIGNCENTER],
compound=tk.LEFT, variable=self.alignment, value=tk.CENTER,
command=self.toggle_alignment)
viewMenu.add_radiobutton(label=ALIGN_RIGHT, underline=6,
image=self.menuImages[ALIGNRIGHT],
compound=tk.LEFT, variable=self.alignment, value=tk.RIGHT,
command=self.toggle_alignment)
self.menubar.add_cascade(label="View", underline=0,
menu=viewMenu)
示例12: create_alignment_toolbar
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def create_alignment_toolbar(self):
settings = TkUtil.Settings.Data
self.alignmentToolbar = ttk.Frame(self.toolbarFrame,
relief=tk.RAISED)
self.alignmentToolbar.text = ALIGNMENT_TOOLBAR
self.alignmentToolbar.underline = 0
menuButton = ttk.Button(self.alignmentToolbar,
text="Alignment Toolbar Menu",
image=self.toolbarImages[TOOLBARMENU],
command=self.toolbar_menu)
TkUtil.bind_context_menu(menuButton, self.toolbar_menu)
TkUtil.Tooltip.Tooltip(menuButton, text="Alignment Toolbar Menu")
self.leftButton = ttk.Button(self.alignmentToolbar,
text=ALIGN_LEFT, image=self.toolbarImages[ALIGNLEFT])
self.leftButton.config(
command=lambda: self.toggle_alignment(tk.LEFT))
TkUtil.Tooltip.Tooltip(self.leftButton, text=ALIGN_LEFT)
self.centerButton = ttk.Button(self.alignmentToolbar,
text=ALIGN_CENTER,
image=self.toolbarImages[ALIGNCENTER])
self.centerButton.config(
command=lambda: self.toggle_alignment(tk.CENTER))
TkUtil.Tooltip.Tooltip(self.centerButton, text=ALIGN_CENTER)
self.rightButton = ttk.Button(self.alignmentToolbar,
text=ALIGN_RIGHT, image=self.toolbarImages[ALIGNRIGHT])
self.rightButton.config(
command=lambda: self.toggle_alignment(tk.RIGHT))
TkUtil.Tooltip.Tooltip(self.rightButton, text=ALIGN_RIGHT)
TkUtil.add_toolbar_buttons(self.alignmentToolbar, (menuButton,
self.leftButton, self.centerButton, self.rightButton))
self.toolbars.append(self.alignmentToolbar)
self.leftButton.state((TkUtil.SELECTED,))
self.alignment.set(tk.LEFT)
示例13: toggle_alignment
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def toggle_alignment(self, alignment=None):
if alignment is None:
alignment = self.alignment.get()
else:
self.alignment.set(alignment)
for button, value in ((self.leftButton, tk.LEFT),
(self.centerButton, tk.CENTER),
(self.rightButton, tk.RIGHT)):
if value == alignment:
button.state((TkUtil.SELECTED,))
self.editor.align(alignment)
else:
button.state((TkUtil.NOT_SELECTED,))
示例14: context_menu
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def context_menu(self, event):
modifier = TkUtil.menu_modifier()
menu = tk.Menu(self.master)
if self.editor.text.tag_ranges(tk.SEL):
menu.add_command(label=COPY, underline=0,
command=lambda: self.editor.text.event_generate(
"<<Copy>>"), image=self.menuImages[COPY],
compound=tk.LEFT, accelerator=modifier + "+C")
menu.add_command(label=CUT, underline=2,
command=lambda: self.editor.text.event_generate(
"<<Cut>>"), image=self.menuImages[CUT],
compound=tk.LEFT, accelerator=modifier + "+X")
menu.add_command(label=PASTE, underline=0,
command=lambda: self.editor.text.event_generate(
"<<Paste>>"), image=self.menuImages[PASTE],
compound=tk.LEFT, accelerator=modifier + "+V")
menu.add_separator()
menu.add_checkbutton(label=BOLD, underline=0,
image=self.menuImages[BOLD], compound=tk.LEFT,
variable=self.bold,
command=lambda: self.toggle_button(self.boldButton))
menu.add_checkbutton(label=ITALIC, underline=0,
image=self.menuImages[ITALIC], compound=tk.LEFT,
variable=self.italic,
command=lambda: self.toggle_button(self.italicButton))
menu.add_separator()
menu.add_radiobutton(label=ALIGN_LEFT, underline=6,
image=self.menuImages[ALIGNLEFT], compound=tk.LEFT,
variable=self.alignment, value=tk.LEFT,
command=self.toggle_alignment)
menu.add_radiobutton(label=ALIGN_CENTER, underline=6,
image=self.menuImages[ALIGNCENTER],
compound=tk.LEFT, variable=self.alignment, value=tk.CENTER,
command=self.toggle_alignment)
menu.add_radiobutton(label=ALIGN_RIGHT, underline=6,
image=self.menuImages[ALIGNRIGHT],
compound=tk.LEFT, variable=self.alignment, value=tk.RIGHT,
command=self.toggle_alignment)
menu.tk_popup(event.x_root, event.y_root)
示例15: create_ui
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import CENTER [as 别名]
def create_ui(self):
self.helpLabel = ttk.Label(self, text=_TEXT, background="white",
justify=tk.CENTER)
self.closeButton = TkUtil.Button(self, text="Close", underline=0)
self.helpLabel.pack(anchor=tk.N, expand=True, fill=tk.BOTH,
padx=PAD, pady=PAD, ipadx="2m", ipady="2m")
self.closeButton.pack(anchor=tk.S)
self.protocol("WM_DELETE_WINDOW", self.close)
if not TkUtil.mac():
self.bind("<Alt-c>", self.close)
self.bind("<Escape>", self.close)
self.bind("<Expose>", self.reposition)