本文整理匯總了Python中Tkinter.X屬性的典型用法代碼示例。如果您正苦於以下問題:Python Tkinter.X屬性的具體用法?Python Tkinter.X怎麽用?Python Tkinter.X使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類Tkinter
的用法示例。
在下文中一共展示了Tkinter.X屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _init_toolbar
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def _init_toolbar(self):
xmin, xmax = self.canvas.figure.bbox.intervalx
height, width = 50, xmax-xmin
Tk.Frame.__init__(self, master=self.window,
width=int(width), height=int(height),
borderwidth=2)
self.update() # Make axes menu
for text, tooltip_text, image_file, callback in self.toolitems:
if text is None:
# spacer, unhandled in Tk
pass
else:
button = self._Button(text=text, file=image_file,
command=getattr(self, callback))
if tooltip_text is not None:
ToolTip.createToolTip(button, tooltip_text)
self.message = Tk.StringVar(master=self)
self._message_label = Tk.Label(master=self, textvariable=self.message)
self._message_label.pack(side=Tk.RIGHT)
self.pack(side=Tk.BOTTOM, fill=Tk.X)
示例2: show_mnemonic_gui
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def show_mnemonic_gui(mnemonic_sentence):
"""may be called *after* main() to display the successful result iff the GUI is in use
:param mnemonic_sentence: the mnemonic sentence that was found
:type mnemonic_sentence: unicode
:rtype: None
"""
assert tk_root
global pause_at_exit
padding = 6
tk.Label(text="WARNING: seed information is sensitive, carefully protect it and do not share", fg="red") \
.pack(padx=padding, pady=padding)
tk.Label(text="Seed found:").pack(side=tk.LEFT, padx=padding, pady=padding)
entry = tk.Entry(width=80, readonlybackground="white")
entry.insert(0, mnemonic_sentence)
entry.config(state="readonly")
entry.select_range(0, tk.END)
entry.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=padding, pady=padding)
tk_root.deiconify()
tk_root.lift()
entry.focus_set()
tk_root.mainloop() # blocks until the user closes the window
pause_at_exit = False
示例3: x_adjust
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def x_adjust(self):
x=[]
y=[]
if self.lb_coords.size()==0:
pass
elif self.shift_x_entry.get()=='':
self.label_error.configure(text = 'Input X amount to Shift')
else:
coords_raw = self.lb_coords.get(0,tk.END)
for line in coords_raw:
coords = line.split(',')
x.append(float(coords[0])+float(self.shift_x_entry.get()))
y.append(float(coords[1]))
for i in range(len(x)):
new_coords = '{0:.3f},{1:.3f}'.format(x[i],y[i])
self.lb_coords.delete(i)
self.lb_coords.insert(i,new_coords)
self.refreshFigure()
self.ins_validate()
示例4: canvClick
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def canvClick(self, event):
try:
x = int(self.canvas1.canvasx(event.x) / self.root.zoomMult)
y = int(self.canvas1.canvasy(event.y) / self.root.zoomMult)
w, h = self.root.im.size
if 0 <= x < w and 0 <= y < h:
tk_rgb = "#%02x%02x%02x" % self.root.im.getpixel((x, y))
self.canvas2.config(bg=tk_rgb)
rgb = "R: %d; G: %d; B: %d;" % self.root.im.getpixel((x, y))
self.v.set(rgb)
xy = "X: %d; Y: %d;" % (x, y)
self.xy.set(xy)
else:
rgb = "X,Y Out of Range"
self.v.set(rgb)
except ValueError:
pass
示例5: addMessageFrame
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def addMessageFrame(self):
frame=Frame(self)
frame.pack(fill=tk.BOTH,side=tk.TOP,\
expand=1,padx=8,pady=5)
self.messagelabel=tk.Label(frame,text='Message',bg='#bbb')
self.messagelabel.pack(side=tk.TOP,fill=tk.X)
self.text=tk.Text(frame)
self.text.pack(side=tk.TOP,fill=tk.BOTH,expand=1)
self.text.height=10
scrollbar=tk.Scrollbar(self.text)
scrollbar.pack(side=tk.RIGHT,fill=tk.Y)
self.text.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=self.text.yview)
示例6: generate_city_pic
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def generate_city_pic(self, city_data):
"""
生成城市數據圖片
因為plt在子線程中執行會出現自動彈出彈框並阻塞主線程的行為,plt行為均放在主線程中
:param data:
:return:
"""
font = {'family': ['xkcd', 'Humor Sans', 'Comic Sans MS'],
'weight': 'bold',
'size': 12}
matplotlib.rc('font', **font)
cities = city_data['cities']
city_people = city_data['city_people']
# 繪製「性別分布」柱狀圖
plt.barh(range(len(cities)), width=city_people, align='center', color=self.bar_color, alpha=0.8)
# 添加軸標簽
plt.xlabel(u'Number of People')
# 添加標題
plt.title(u'Top %d Cities of your friends distributed' % len(cities), fontsize=self.title_font_size)
# 添加刻度標簽
plt.yticks(range(len(cities)), cities)
# 設置X軸的刻度範圍
plt.xlim([0, city_people[0] * 1.1])
# 為每個條形圖添加數值標簽
for x, y in enumerate(city_people):
plt.text(y + len(str(y)), x, y, ha='center')
# 顯示圖形
plt.savefig(ALS.result_path + '/4.png')
# todo 如果調用此處的關閉,就會導致應用本身也被關閉
# plt.close()
# plt.show()
示例7: int_to_bytes
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def int_to_bytes(int_rep, min_length):
"""convert an unsigned integer to a string of bytes (in big-endian order)
:param int_rep: a non-negative integer
:type int_rep: long or int
:param min_length: the minimum output length
:type min_length: int
:return: the raw bytes, zero-padded (at the beginning) if necessary
:rtype: str
"""
assert int_rep >= 0
hex_rep = "{:X}".format(int_rep)
if len(hex_rep) % 2 == 1: # The hex decoder below requires
hex_rep = "0" + hex_rep # exactly 2 chars per byte.
return base64.b16decode(hex_rep).rjust(min_length, "\0")
示例8: edition_change
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def edition_change(self, *event):
self.shape_type_menu.destroy()
edition = self.edition_type.get()
edition_index = self.edition.index(edition)
self.shape_type_menu = tk.OptionMenu(self.menu_frame, self.shape_type, *self.shape_sets[edition_index], command=self.shape_change)
helv = tkFont.Font(family='Helvetica',size=self.f_size, weight='bold')
self.shape_type_menu.config(font=helv)
self.shape_type_menu.pack(side=tk.TOP, fill=tk.X, expand=True)
self.shape_type.set(self.shape_sets[edition_index][0])
示例9: picture_tool
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def picture_tool(filename = None):
"""Allows you to find information about digital images.
The PictureTool's Toolbar:
Once you have opened an image, you can view information about its
individual pixels by looking at the toolbar. To select a pixel drag
(click and hold down) the mouse to the position you want and then
release it to hold that position's information in the toolbar.
The following information in the toolbar changes to reflect the
properties of the pixel you selected:
X = the x coordinate of the pixel (starting with 0, counting from the left)
Y = the y coordinate of the pixel (starting with 0, counting from the top)
R = the Red value of the pixel (0 to 255)
G = the Green value of the pixel (0 to 255)
B = the Blue value of the pixel (0 to 255)
In addition, the box at the far right displays the color of the pixel.
Zooming in/out:
To Zoom, select the amount of zoom you want from the zoom menu.
Less than 100% zooms out and more than 100% zooms in.
The 100% zoom level will always return you to your orginal picture.
filename: a string representing the location and name of picture.
If no filename is given, a file-chooser opens."""
if not filename:
filename = _easygui.fileopenbox("Select an image",
_sys.argv[0], '*',
[ [ "*.jpg", "*.png", "*.bmp", "*.gif",
"Image files" ] ])
if not filename:
raise RuntimeError("No image file selected.")
img = load_picture(filename)
tool = PictureTool(img)
tool.run_tool()
# --------------------------------------------------------------------
示例10: addPathFrame
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def addPathFrame(self):
frame=Frame(self)
frame.pack(fill=tk.X,expand=0,side=tk.TOP,padx=8,pady=5)
frame.columnconfigure(1,weight=1)
#------------------Database file------------------
label=tk.Label(frame,text='Mendeley Data file:',\
bg='#bbb')
label.grid(row=0,column=0,\
sticky=tk.W,padx=8)
self.db_entry=tk.Entry(frame)
self.db_entry.grid(row=0,column=1,sticky=tk.W+tk.E,padx=8)
self.db_button=tk.Button(frame,text='Open',command=self.openFile)
self.db_button.grid(row=0,column=2,padx=8,sticky=tk.E)
hint='''
Default location on Linux:
~/.local/share/data/Mendeley\ Ltd./Mendeley\ Desktop/your_email@www.mendeley.com.sqlite
Default location on Windows:
C:\Users\Your_name\AppData\Local\Mendeley Ltd\Mendeley Desktop\your_email@www.mendeley.com.sqlite'''
hint_label=tk.Label(frame,text=hint,\
justify=tk.LEFT,anchor=tk.NW)
hint_label.grid(row=1,column=0,columnspan=3,\
sticky=tk.W,padx=8)
#--------------------Output dir--------------------
label2=tk.Label(frame,text='Output folder:',\
bg='#bbb')
label2.grid(row=2,column=0,\
sticky=tk.W,padx=8)
self.out_entry=tk.Entry(frame)
self.out_entry.grid(row=2,column=1,sticky=tk.W+tk.E,padx=8)
self.out_button=tk.Button(frame,text='Choose',command=self.openDir)
self.out_button.grid(row=2,column=2,padx=8,sticky=tk.E)
示例11: __init__
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def __init__(self, canvas, window):
self.canvas = canvas
self.window = window
xmin, xmax = canvas.figure.bbox.intervalx
height, width = 50, xmax-xmin
Tk.Frame.__init__(self, master=self.window,
width=int(width), height=int(height),
borderwidth=2)
self.update() # Make axes menu
self.bLeft = self._Button(
text="Left", file="stock_left",
command=lambda x=-1: self.panx(x))
self.bRight = self._Button(
text="Right", file="stock_right",
command=lambda x=1: self.panx(x))
self.bZoomInX = self._Button(
text="ZoomInX",file="stock_zoom-in",
command=lambda x=1: self.zoomx(x))
self.bZoomOutX = self._Button(
text="ZoomOutX", file="stock_zoom-out",
command=lambda x=-1: self.zoomx(x))
self.bUp = self._Button(
text="Up", file="stock_up",
command=lambda y=1: self.pany(y))
self.bDown = self._Button(
text="Down", file="stock_down",
command=lambda y=-1: self.pany(y))
self.bZoomInY = self._Button(
text="ZoomInY", file="stock_zoom-in",
command=lambda y=1: self.zoomy(y))
self.bZoomOutY = self._Button(
text="ZoomOutY",file="stock_zoom-out",
command=lambda y=-1: self.zoomy(y))
self.bSave = self._Button(
text="Save", file="stock_save_as",
command=self.save_figure)
self.pack(side=Tk.BOTTOM, fill=Tk.X)
示例12: show_error_dialog
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def show_error_dialog(self, title, message_text, exception):
# ToDo: Check Windows behavior!! --> -disable
self._root.wm_attributes("-topmost", False)
err_dialog = Tk.Toplevel(self._frame)
err_dialog.minsize(300, 400)
err_dialog.transient(self._frame)
err_dialog.focus_force()
err_dialog.grab_set()
def add_textview(header, text):
err_dialog_frame = Tk.Frame(err_dialog)
err_dialog_label = Tk.Label(err_dialog_frame, text=header)
err_dialog_label.pack(side='top', fill=Tk.X)
err_dialog_text = Tk.Text(err_dialog_frame, height=10)
err_dialog_text.insert(Tk.END, text)
err_dialog_text.pack(side='left', fill=Tk.Y)
err_dialog_scrollbar = Tk.Scrollbar(err_dialog_frame)
err_dialog_scrollbar.pack(side='right', fill=Tk.Y)
err_dialog_scrollbar.config(command=err_dialog_text.yview)
err_dialog_text.config(yscrollcommand=err_dialog_scrollbar.set)
err_dialog_frame.pack(side='top')
def close_error_dialog():
# ToDo: Check Windows behavior!! -disable
self._root.wm_attributes("-topmost", True)
err_dialog.destroy()
err_dialog.protocol("WM_DELETE_WINDOW", close_error_dialog)
add_textview(message_text, str(exception))
if isinstance(exception, TexTextCommandFailed):
if exception.stdout:
add_textview('Stdout:', exception.stdout.decode('utf-8'))
if exception.stderr:
add_textview('Stderr:', exception.stderr.decode('utf-8'))
close_button = Tk.Button(err_dialog, text='OK', command=close_error_dialog)
close_button.pack(side='top', fill='x', expand=True)
示例13: retryskipabort
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def retryskipabort(message, timeout=20):
"""
Show dialog of RETRY,SKIP,ABORT
Returns:
one of "retry", "skip", "abort"
"""
root = tk.Tk()
root.geometry("400x200")
root.title("Exception handle")
root.eval('tk::PlaceWindow %s center' % root.winfo_pathname(root.winfo_id()))
root.attributes("-topmost", True)
_kvs = {"result": "abort"}
def cancel_timer(*args):
root.after_cancel(_kvs['root'])
root.title("Manual")
def update_prompt():
cancel_timer()
def f(result):
def _inner():
_kvs['result'] = result
root.destroy()
return _inner
tk.Label(root, text=message).pack(side=tk.TOP, fill=tk.X, pady=10)
frmbtns = tk.Frame(root)
tk.Button(frmbtns, text="Skip", command=f('skip')).pack(side=tk.LEFT)
tk.Button(frmbtns, text="Retry", command=f('retry')).pack(side=tk.LEFT)
tk.Button(frmbtns, text="ABORT", command=f('abort')).pack(side=tk.LEFT)
frmbtns.pack(side=tk.BOTTOM)
prompt = tk.StringVar()
label1 = tk.Label(root, textvariable=prompt) #, width=len(prompt))
label1.pack()
deadline = time.time() + timeout
def _refresh_timer():
leftseconds = deadline - time.time()
if leftseconds <= 0:
root.destroy()
return
root.title("Test will stop after " + str(int(leftseconds)) + " s")
_kvs['root'] = root.after(500, _refresh_timer)
_kvs['root'] = root.after(0, _refresh_timer)
root.bind('<Button-1>', cancel_timer)
root.mainloop()
return _kvs['result']
示例14: test
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def test():
root = tk.Tk()
scrollbar = simultaneousScrollbar(root, orient=tk.HORIZONTAL)
scrollbar.pack(side=tk.TOP, fill=tk.X)
emptySpace = tk.Frame(root, height=18)
emptySpace.pack()
tk.Label(root, text='First scrolled frame:').pack(anchor=tk.W)
canvas1 = tk.Canvas(root, width=300, height=100)
canvas1.pack(anchor=tk.NW)
frame1= tk.Frame(canvas1)
frame1.pack()
for i in range(20):
tk.Label(frame1, text="Label "+str(i)).pack(side=tk.LEFT)
canvas1.create_window(0, 0, window=frame1, anchor='nw')
canvas1.update_idletasks()
canvas1['scrollregion'] = (0,0,frame1.winfo_reqwidth(), frame1.winfo_reqheight())
tk.Label(root, text='Second scrolled frame:').pack(anchor=tk.W)
canvas2 = tk.Canvas(root,width=300, height=100)
canvas2.pack(anchor=tk.NW)
frame2= tk.Frame(canvas2)
frame2.pack()
for i in range(20):
tk.Label(frame2, text="Label "+str(i)).pack(side=tk.LEFT)
canvas2.create_window(0, 0, window=frame2, anchor='nw')
canvas2.update_idletasks()
canvas2['scrollregion'] = (0,0,frame2.winfo_reqwidth(), frame2.winfo_reqheight())
scrollbar.add_ScrollableArea(canvas1,canvas2)
MouseWheel(root).add_scrolling(canvas1, xscrollbar=scrollbar)
MouseWheel(root).add_scrolling(canvas2, xscrollbar=scrollbar)
root.mainloop()
示例15: loads_base_material_input_gui
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import X [as 別名]
def loads_base_material_input_gui(self):
tk.Label(self.tab_loads, text="** All Loads Assumed to Act at the Weld Group Centroid**", font=self.f_type_b_big).grid(row=0,column=0,columnspan=6, sticky = tk.W)
tk.Label(self.tab_loads, text="Loading:", font=self.f_type_b).grid(row=1,column=0, sticky = tk.W)
tk.Label(self.tab_loads, text="Materials:", font=self.f_type_b).grid(row=1,column=3, sticky = tk.W)
load_labels = ['Fz (lbs)= \nAxial', 'Fx (lbs)= \nShear X', 'Fy (lbs)= \nShear Y', 'Mx (in-lbs)= \nMoment About X', 'My (in-lbs)= \nMoment About Y', 'Mz = (in-lbs)\nMoment About Z']
self.loads_in = [tk.StringVar(), tk.StringVar(), tk.StringVar(), tk.StringVar(), tk.StringVar(), tk.StringVar()]
for load in self.loads_in:
load.set('0.00')
i=0
for label, load in zip(load_labels, self.loads_in):
current_load_row_count = 2+i
tk.Label(self.tab_loads, text=label, font=self.f_type, justify=tk.RIGHT).grid(row=current_load_row_count,column=0, sticky = tk.E)
tk.Entry(self.tab_loads, textvariable=load, width=20).grid(row=current_load_row_count,column=1, sticky = tk.W)
i+=1
material_labels = ['Fexx,weld (ksi)= ','Fy,base 1 (ksi) = ','Fu,base 1 (ksi)= ','t,base 1 (in) = ','Fy,base 2 (ksi) = ','Fu,base 2 (ksi)= ','t,base 2 (in) = ']
self.material_in = [tk.StringVar(),tk.StringVar(),tk.StringVar(),tk.StringVar(),tk.StringVar(),tk.StringVar(),tk.StringVar()]
default_material = ['70.00','36.00','58.00','0.375','36.00','58.00','0.375']
for material, default in zip(self.material_in, default_material):
material.set(default)
y=0
for material_label, material in zip(material_labels,self.material_in):
current_material_row_count = 2+y
tk.Label(self.tab_loads, text=material_label, font=self.f_type, justify=tk.RIGHT).grid(row=current_material_row_count,column=3, sticky = tk.E)
tk.Entry(self.tab_loads, textvariable=material, width=15).grid(row=current_material_row_count,column=4, sticky = tk.W)
y+=1
self.run_analysis_button = tk.Button(self.tab_loads,text = "Run Analysis (Quadrant)", command = self.force_analysis, font=self.f_type_b)
self.run_analysis_button.grid(row=current_load_row_count+1, column=0, columnspan=2, pady=10)
self.run_analysis_segment_button = tk.Button(self.tab_loads,text = "Run Analysis (Segment)", command = self.force_analysis_segment, font=self.f_type_b)
self.run_analysis_segment_button.grid(row=current_load_row_count+2, column=0, columnspan=2, pady=10)
self.run_analysis_conservative_button = tk.Button(self.tab_loads,text = "Run Analysis (Conservative)", command = self.force_analysis_conservative, font=self.f_type_b)
self.run_analysis_conservative_button.grid(row=current_load_row_count+3, column=0, columnspan=2, pady=10)
self.design_asd = tk.IntVar()
tk.Checkbutton(self.tab_loads , text=' : Loads are Nominal (ASD)', variable=self.design_asd, font=self.f_type_b).grid(row=current_material_row_count+1, column=4, sticky = tk.W)
self.run_design_button = tk.Button(self.tab_loads,text = "Run AISC Design", command = self.aisc_design, font=self.f_type_b)
self.run_design_button.grid(row=current_material_row_count+2, column=3, columnspan=2, pady=10)