本文整理汇总了Python中Tkinter.Frame.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.bind方法的具体用法?Python Frame.bind怎么用?Python Frame.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Frame
的用法示例。
在下文中一共展示了Frame.bind方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
class filterswindow:
'''
Interface graphique recapitulant les caracteristique du sismogramme
presentant les options de filtrage et de calculs du noyau de sensibilite
'''
def __init__(self,racine):
self.canvas = Canvas(racine, borderwidth=1, background="#ffffff")
self.frame = Frame(self.canvas, background="#ffffff")
self.vsb = Scrollbar(racine, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas.create_window((4,4), window=self.frame, anchor="nw", tags="self.frame")
self.frame.bind("<Configure>", self.OnFrameConfigure)
self.data()
def data(self):
global filterVar
filterVar = 1
global text6a
text6a = "1"
global text6c1
text6c1 = StringVar()
global text6c2
text6c2 = StringVar()
global text6c3
text6c3 = StringVar()
Label(self.frame, text="Option Filter").grid(row=0)
Label(self.frame, text="\n").grid(row=1)
Label(self.frame, text="lowest frequency ?").grid(row=4)
e1 = Entry(self.frame, textvariable=text6c1)
e1.grid(row=5)
Label(self.frame, text="highest frequency ?").grid(row=20)
e2 = Entry(self.frame, textvariable=text6c2)
e2.grid(row=21)
Label(self.frame, text="number of poles ?").grid(row=22)
e3 = Entry(self.frame, textvariable=text6c3)
e3.grid(row=23)
Button(self.frame, text="continue", command=self.quitter).grid(row=24)
def quitter(self):
global racine
racine.destroy()
afficheSismoFiltre(textPath.get(), float(text6c1.get()), float(text6c2.get()), float(text6c3.get()))
def OnFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
示例2: createCanvas
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
def createCanvas( self ):
"Create and return our scrolling canvas frame."
f = Frame( self )
canvas = Canvas( f, width=self.cwidth, height=self.cheight,
bg=self.bg )
# Scroll bars
xbar = Scrollbar( f, orient='horizontal', command=canvas.xview )
ybar = Scrollbar( f, orient='vertical', command=canvas.yview )
canvas.configure( xscrollcommand=xbar.set, yscrollcommand=ybar.set )
# Resize box
resize = Label( f, bg='white' )
# Layout
canvas.grid( row=0, column=1, sticky='nsew')
ybar.grid( row=0, column=2, sticky='ns')
xbar.grid( row=1, column=1, sticky='ew' )
resize.grid( row=1, column=2, sticky='nsew' )
# Resize behavior
f.rowconfigure( 0, weight=1 )
f.columnconfigure( 1, weight=1 )
f.grid( row=0, column=0, sticky='nsew' )
f.bind( '<Configure>', lambda event: self.updateScrollRegion() )
# Mouse bindings
canvas.bind( '<ButtonPress-1>', self.clickCanvas )
canvas.bind( '<B1-Motion>', self.dragCanvas )
canvas.bind( '<ButtonRelease-1>', self.releaseCanvas )
return f, canvas
示例3: initUI
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
def initUI(self):
#top frame using all the remaining space
innerTopFrame = Frame(self, background="black")
innerTopFrame.pack(fill=BOTH, expand=1)
#CLOSE Label
innerBottomLeftFrame = Frame(self, background="black")
innerBottomLeftFrame.place(x=0, width=self.wRoot/2,
y=self.hRoot-200, height=200)
closeLabel = Label(innerBottomLeftFrame, bg="black", fg="black",
text="CLOSE", font=("Comic Sans MS", 48, "bold"))
innerBottomLeftFrame.bind("<Enter>", lambda f: closeLabel.config(fg="white"))
innerBottomLeftFrame.bind("<Leave>", lambda f: closeLabel.config(fg="black"))
innerBottomLeftFrame.bind("<Button-1>", lambda f: self.root.quit())
closeLabel.bind("<Button-1>", lambda f: self.root.quit())
closeLabel.pack(fill=BOTH)
#SHUT DOWN Label
innerBottomRightFrame = Frame(self, background="black")
innerBottomRightFrame.place(x=self.wRoot/2, width=self.wRoot/2,
y=self.hRoot-200, height=200)
shutdownLabel = Label(innerBottomRightFrame, bg="black", fg="black",
text="SHUT DOWN", font=("Comic Sans MS", 48, "bold"))
innerBottomRightFrame.bind("<Enter>", lambda f: shutdownLabel.config(fg="white"))
innerBottomRightFrame.bind("<Leave>", lambda f: shutdownLabel.config(fg="black"))
innerBottomRightFrame.bind("<Button-1>", self.shutdown)
shutdownLabel.bind("<Button-1>", self.shutdown)
shutdownLabel.pack(fill=BOTH)
#design the FullScreenApp
self.pack(fill=BOTH, expand=1)
示例4: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
class RecapCalculs:
'''
Interface graphique recapitulant les caracteristique du sismogramme
presentant les options de filtrage et de calculs du noyau de sensibilite
'''
def __init__(self,root):
self.canvas = Canvas(root, borderwidth=1, background="#ffffff")
self.frame = Frame(self.canvas, background="#ffffff")
self.vsb = Scrollbar(root, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas.create_window((4,4), window=self.frame, anchor="nw", tags="self.frame")
self.frame.bind("<Configure>", self.OnFrameConfigure)
self.data()
def data(self):
self.message = Label(self.frame, text="Recapitulatif du sismogramme").grid(row=0)
global X
X=read(textPath.get())
self.recap = Listbox(self.frame, height = 15, width = 50)
self.recap.insert(1, "network: {}\n".format(X[0].stats.network))
self.recap.insert(2, "station: {}\n".format(X[0].stats.station))
self.recap.insert(3, "location: {}\n".format(X[0].stats.location))
self.recap.insert(4, "channel: {}\n".format(X[0].stats.channel))
self.recap.insert(5, "start time: {}\n".format(X[0].stats.starttime))
self.recap.insert(6, "end time: {}\n".format(X[0].stats.endtime))
self.recap.insert(7, "sampling rate: {}\n".format(X[0].stats.sampling_rate))
self.recap.insert(8, "delta: {}\n".format(X[0].stats.delta))
self.recap.insert(9, "number points: {}\n".format(X[0].stats.npts))
self.recap.insert(10, "calibration: {}\n".format(X[0].stats.calib))
self.recap.insert(11, "event latitude: {}\n".format(X[0].stats.sac.evla))
self.recap.insert(12, "event longitude: {}\n".format(X[0].stats.sac.evlo))
self.recap.insert(13, "event depth: {}\n".format(X[0].stats.sac.evdp))
self.recap.insert(14, "station latitude: {}\n".format(X[0].stats.sac.stla))
self.recap.insert(15, "station longitude: {}\n".format(X[0].stats.sac.stlo))
self.recap.grid(row=0)
#afficheGraphique()
def OnFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
示例5: ValideEvent
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
class EventManager:
"""Object used to manage callback functions for the events of a Widget
Public Methods:
ValideEvent(eventType)
AddCallback(eventType, callback)
SetCallback(func)
RemoveCallback(eventType, func)
ListBindings(event=None)
"""
# NOT USED, imstead I simply try to bind to a dummy widget to check if
# the given event type is valid
#
# eventTypes = ('Key', 'KeyPress', 'KeyPress',
# 'Button', 'ButtonPress', 'ButtonRelease',
# 'Enter', 'Leave', 'Motion')
#
# eventModifiers = ('Control' 'Shift', 'Lock',
# 'Button1', 'B1', 'Button2', 'B2','Button3', 'B3',
# 'Button4', 'B4', 'Button5', 'B5',
# 'Any', 'Double', 'Triple',
# 'Mod1', 'M1', 'Meta', 'M',
# 'Mod2', 'M2', 'Alt',
# 'Mod3', 'M3', 'Mod4', 'M4', 'Mod5', 'M5' )
# buttonDetails = ( '1', '2', '3' )
# keyDetails = any keysym
def __init__(self, widget):
# keys are Tk events, values are lists of callback functions
self.eventHandlers = {}
self.widget = widget
# create a dummy frame to try to bind event to check for event validity
self.dummyFrame = Frame(widget,width=1, height=1)
def DummyCallback(self, event):
"""dummy function used to check event validity"""
pass
def ValideEvent(self, eventType):
"""Check if an event is valide"""
try: self.dummyFrame.bind(eventType, self.DummyCallback)
except: return 0
return 1
def AddCallback(self, eventType, callback):
"""Add a callback fuction"""
assert type(eventType) == type('string')
assert callable(callback)
# Here we should also check that callback has exactly 1 argument
if not self.ValideEvent(eventType):
raise ValueError('%s is not a valide event type' % eventType)
if eventType in self.eventHandlers.keys():
self.eventHandlers[eventType].append(callback)
else:
self.eventHandlers[eventType] = [callback,]
self.widget.bind(eventType, callback, '+')
def BindFuncList(self,eventType, funcList):
"""Bind a list of functions to an event"""
self.widget.bind(eventType, funcList[0])
for f in funcList[1:]:
self.widget.bind(eventType, f, '+')
def HasCallback(self, eventType, callback):
"""Check whether a function is registered as a callback for an event
"""
assert callable(callback)
if self.eventHandlers.has_key(eventType):
for f in self.eventHandlers[eventType]:
if f==callback: return 1
return 0
def SetCallback(self, eventType, callback):
"""Set func as the callback or list of callback functions"""
assert type(eventType) == type('string')
if self.eventHandlers.has_key(eventType):
funcList = self.eventHandlers[eventType]
else: funcList = None
if callable(callback):
self.eventHandlers[eventType] = [callback,]
#.........这里部分代码省略.........
示例6: Example
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.hsv_color = colorsys.rgb_to_hsv(0.0, 0.0, 1.0)
self.hex_color = '#0000ff'
self.color_list = ["red","blue","green","orange","purple"]
self.parent = parent
print "Loading model..."
self.lux = Lux()
fp = open(curdir+"/gauss_model.pkl"); self.gm = pickle.load(fp); fp.close()
fp = open(curdir+"/memoized_binomial_data.pkl"); self.curve_data = pickle.load(fp); fp.close()
fp = open(curdir+"/sampling_normalizer.pkl"); self.normalizer = pickle.load(fp); fp.close()
print "Creating UI"
self.initUI()
self.update_output()
self.replot()
def update_output(self):
(h, s, v) = self.hsv_color
self.hsv_var.set("Hue: \t %2.1f \nSat:\t %2.1f \nValue:\t %2.1f" % (h*360,s*100,v*100))
items = self.lux.full_posterior((h * 360, s * 100, v * 100))
self.current_post = items
desc = [ '{:<25} ({:.3f})\n'.format(items[i][0], items[i][1]) for i in range(25) ]
self.display.config(state=NORMAL)
self.display.delete(0, END)
for i in range(25): self.display.insert(END, '{:<20} ({:.3f})'.format(items[i][0], items[i][1]))
self.display.select_set(0, 0)
def plot_lux_model(self, params,ax1,label,support,dim):
cur_color='black'
mu1,sh1,sc1,mu2,sh2,sc2 = params
left_stach=gam_dist(sh1,scale=sc1); lbounds=left_stach.interval(0.99)
right_stach=gam_dist(sh2,scale=sc2); rbounds=right_stach.interval(0.99)
lx=np.linspace(mu1,-180); rx=np.linspace(mu2,360)
s=3;
ax1.plot(rx, [right_stach.sf(abs(y-mu2)) for y in rx],linewidth=s,c=cur_color);
ax1.plot([1.01*mu1,0.99*mu2], [1.,1.], linewidth=s,c=cur_color)
return ax1.plot(lx,[left_stach.sf(abs(y-mu1)) for y in lx],c=cur_color, linewidth=s);
def plot_gm_model(self, params, ax, label, support):
s=3
x = np.linspace(support[0],support[1],360)
return ax.plot(x,norm.pdf(x,params[0],params[1]),c='red', linewidth=s), norm.pdf([params[0]],params[0],[params[1]])[0]
def initUI(self):
self.parent.title("Interactive LUX visualization")
self.pack(fill=BOTH, expand=1)
self.color_frame = Frame(self, border=1)
self.color_frame.pack(side=LEFT)
probe_title_var = StringVar(); probe_title_label = Label(self.color_frame, textvariable=probe_title_var, justify=CENTER, font = "Helvetica 16 bold italic")
probe_title_var.set("Color Probe X"); probe_title_label.pack(side=TOP)
self.hsv_var = StringVar()
self.hsv_label = Label(self.color_frame, textvariable=self.hsv_var,justify=LEFT)
h,s,v = self.hsv_color
self.hsv_var.set("Hue: %2.1f \nSaturation: %2.1f \nValue: %2.1f" % (h*360,s*100,v*100))
self.hsv_label.pack(side=TOP)
self.frame = Frame(self.color_frame, border=1,
relief=SUNKEN, width=200, height=200)
self.frame.pack(side=TOP)
self.frame.config(bg=self.hex_color)
self.frame.bind("<Button-1>",self.onChoose)
self.btn = Button(self.color_frame, text="Select Color",
command=self.onChoose)
self.btn.pack(side=TOP)
posterior_title_var = StringVar(); posterior_title_label = Label(self.color_frame, textvariable=posterior_title_var, justify=CENTER, font = "Helvetica 16 bold italic")
posterior_title_var.set("\n\nLUX's Posterior"); posterior_title_label.pack(side=TOP)
Label(self.color_frame, text="Double click to show details \n(Wait time dependent on computer)").pack(side=TOP)
my_font = tkFont.Font(family="Courier", size=10)
self.display = Listbox(self.color_frame, border=1,
relief=SUNKEN, width=30, height=25, font=my_font)
self.display.pack(side=TOP,fill=Y,expand=1)
self.display.bind("<Double-Button-1>",self.onSelect)
self.display_btn = Button(self.color_frame, text="Show details", command=self.onSelect)
self.display_btn.pack(side=TOP)
self.update_output()
self.fig = Figure(figsize=(10,4), dpi=100)
#.........这里部分代码省略.........
示例7: OfxConverter
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
#.........这里部分代码省略.........
self.tabFiles.grid_columnconfigure( 0, weight=1 )
def addFile(self,filename,ibans):
if filename != u"" and len(ibans) > 0:
Label(self.tabFiles, text=filename,
borderwidth=3).grid(row=self.row,column=0,sticky=constants.W,padx=1)
ibanList = []
for iban in ibans:
ibanList.append( iban[:8] )
combo = ttk.Combobox(self.tabFiles,values=ibanList)
combo.current(0)
if len(ibanList) == 1:
combo.configure(state=constants.DISABLED)
combo.grid(row=self.row,column=1,sticky=constants.E,padx=1)
state = IntVar()
c = Checkbutton(self.tabFiles,variable=state)
c.grid(row=self.row,column=2)
self.row += 1
ttk.Separator(self.tabFiles).grid(row=self.row, sticky=u"ew", columnspan=3 )
self.row += 1
self.guiMap.append( [ filename, ibans, combo, c, state ] )
def addFileToCustomTab(self,filename):
if filename != u"":
if self.frame:
self.frame.pack_forget()
self.frame.destroy()
self.frame = Frame( self.canvas )
self.canvas.create_window((0,0),window=self.frame,anchor=u'nw')
self.frame.bind(u"<Configure>", self.onFrameConfigure)
file = csv.reader( open(filename) )
lines = 1
transaction = Transaction()
fields = transaction.fields
fields.insert(0,u"main account")
fields.insert(0,self.UNUSED)
self.comboBoxes = []
self.labels = collections.defaultdict(list)
for row in file:
column = 0
for field in row:
if lines == 1:
combo = ttk.Combobox(self.frame,values=transaction.fields,state=u"readonly")
combo.current(0)
combo.grid(row=0,column=column,sticky=constants.W)
self.comboBoxes.append( combo )
combo.bind(u'<<ComboboxSelected>>', self.onComboboxChanged)
nextColumn = column + 1
ttk.Separator(self.frame,orient=constants.VERTICAL).grid(row=0, column=nextColumn, sticky=u"ns")
label = Label(self.frame,text=field,borderwidth=3)
label.grid(row=lines,column=column,sticky=constants.W,padx=1)
self.labels[lines-1].append( label )
column = column + 1
ttk.Separator(self.frame,orient=constants.VERTICAL).grid(row=lines, column=column, sticky=u"ns")
column = column + 1
lines = lines + 1
示例8: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
#.........这里部分代码省略.........
self.linking_warn_option = Checkbutton(self.main_frame, text=link_text,
variable=self.linking_warn)
self.linking_warn_option.pack()
self.debug = BooleanVar()
debug_text = self.options['debug']['label']
self.debug_option = Checkbutton(self.main_frame, text=debug_text,
variable=self.debug)
self.debug_option.pack()
self.extras = BooleanVar()
extras_text = self.options['extras']['label']
self.extras_option = Checkbutton(self.main_frame, text=extras_text,
variable=self.extras)
self.extras_option.pack()
self.convert_label = Label(self.main_frame, text='3. Run conversion.')
self.convert_label.pack()
# Task: Add xscrollcommand and yscrollcommand.
self.convert_button = Button(self.main_frame, text='Convert',
fg='black', command=self.convert)
self.convert_button.pack()
self.log.pack(fill=X, expand=1)
self.log_text('PMA Convert allows you to convert .xls or .xlsx form '
'definition files to files which are compatible with ODK '
'Collect.\n\nIf you need to copy and paste from this '
'log, highlight the text and press CTRL+C to copy. Then '
'press CTRL+V to paste.\n\n'
'====================================================\n\n'
'Awaiting file selection.')
# Task: Fix menus. They're not working.
self.context_menu = Menu(self.main_frame, tearoff=0)
self.context_menu.add_command(label="Convert", command=self.convert)
self.main_frame.bind("<Button-3>", self.popup)
# - Note: Strangely this stopped anchoring to bottom suddenly, for some
# reason. So it is temporarily disabled.
self.status_bar = Label(self.main_frame,
text='Awaiting file selection.',
bd=1, relief=SUNKEN, anchor=W)
if gui_config['status_bar_on'] is True:
self.status_bar.pack(side=BOTTOM, fill=X)
# Run
root.mainloop()
# Functions
def popup(self, event):
# Note: Currently doesn't work.
self.context_menu.post(event.x_root, event.y_root)
# display the popup menu
try:
self.context_menu.tk_popup(event.x_root, event.y_root, 0)
finally:
# make sure to release the grab (Tk 8.0a1 only)
self.context_menu.grab_release()
def position_main_frame(self, orientation):
if orientation == 'center':
x, y, a = .5, .5, 'c'
return self.main_frame.place(relx=x, rely=y, anchor=a)
elif orientation == 'top':
return self.main_frame.pack()
else:
return self.main_frame.pack()
示例9: Chord
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
class Chord(Frame):
RIGHT_ARROW_ICON = 'I2RlZmluZSBpbWFnZV93aWR0aCAxNwojZGVmaW5lIGltYWdlX2hlaWdodCAxNwpzdGF0aWMgY2hhciBpbWFnZV9iaXRzW10gPSB7CjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLAoweDYwLDB4MDAsMHgwMCwweGUwLDB4MDAsMHgwMCwweGUwLDB4MDMsMHgwMCwweGUwLDB4MGYsMHgwMCwweGUwLDB4MDMsMHgwMCwKMHhlMCwweDAxLDB4MDAsMHg2MCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsCjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwCn07'
DOWN_ARROW_ICON = 'I2RlZmluZSBpbWFnZV93aWR0aCAxNwojZGVmaW5lIGltYWdlX2hlaWdodCAxNwpzdGF0aWMgY2hhciBpbWFnZV9iaXRzW10gPSB7CjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLAoweDAwLDB4MDAsMHgwMCwweGUwLDB4MGYsMHgwMCwweGUwLDB4MGYsMHgwMCwweGMwLDB4MDcsMHgwMCwweGMwLDB4MDMsMHgwMCwKMHg4MCwweDAzLDB4MDAsMHgwMCwweDAxLDB4MDAsMHgwMCwweDAxLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsCjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwCn07'
def __init__(self, master, title, width, body_background="white", background="#f0f0f0", foreground="#333333", selected_background="#1ba1e2", selected_foreground="white", active_foreground="#0067cb", cursor="hand1"):
Frame.__init__(self, master, background="white")
self._title = title
self._background = background
self._foreground = foreground
self._active_foreground = active_foreground
self._selected_foreground = selected_foreground
self._selected_background = selected_background
self._cursor = cursor
self._right_arrow_icon = BitmapImage(data=base64.b64decode(Chord.RIGHT_ARROW_ICON))
self._down_arrow_icon = BitmapImage(data=base64.b64decode(Chord.DOWN_ARROW_ICON))
self._caption = Frame(self, width =width, background=background, padx=2)
self._caption.pack(fill=X, pady=(0,2))
self._caption.pack_propagate(False)
self._icon_label = Label(self._caption, image=self._right_arrow_icon, background=background)
self._icon_label.pack(side=LEFT)
self._title_label = Label(self._caption, text=title, bg = background, fg=foreground)
self._title_label.pack(side=LEFT, padx=4, fill=X)
self._caption.configure(height= self._title_label.winfo_reqheight())
self.body = Frame(self, background=body_background)
self._body_height = None
self._is_opened = False
self._is_animating = False
self._caption.bind('<Button-1>', self._on_click)
self._title_label.bind('<Button-1>', self._on_click)
self._icon_label.bind('<Button-1>', self._on_click)
self._caption.bind('<Enter>', self._on_enter)
self._caption.bind('<Leave>', self._on_leave)
@property
def title(self):
return self._title
@title.setter
def title(self, text):
self._title = text
self._title_label.configure(text=text)
def _on_enter(self, event):
if not self._is_opened:
self._down_arrow_icon.configure(foreground=self._active_foreground)
self._right_arrow_icon.configure(foreground=self._active_foreground)
self.config(cursor=self._cursor)
def _on_leave(self, event):
if not self._is_opened:
self._down_arrow_icon.configure(foreground=self._foreground)
self._right_arrow_icon.configure(foreground=self._foreground)
self.config(cursor="arrow")
def _on_click(self, event):
if self._is_animating: return
self.toggle()
def open(self):
if self._is_animating: return
if not self._is_opened: self._open()
def _open(self):
self.body.pack()
self.body.pack_propagate(False)
self._icon_label.configure(image=self._down_arrow_icon, background = self._selected_background)
self._title_label.configure(foreground= self._selected_foreground, background = self._selected_background)
self._caption.configure(background = self._selected_background)
self._down_arrow_icon.configure(foreground=self._selected_foreground)
if self._body_height is None:
self._body_height= self.body.winfo_reqheight()
end_value = self._body_height
self.body.configure(width=self.winfo_width())
self._is_opened = True
self._is_animating = True
animation = Animation(
self,
ticks=16,
interval_time=0.01,
#.........这里部分代码省略.........
示例10: Scrolling_Area
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
class Scrolling_Area(Frame, object):
def __init__(self, master, width=None, height=None, mousewheel_speed = 2, scroll_horizontally=True, xscrollbar=None, scroll_vertically=True, yscrollbar=None, outer_background=None, inner_frame=Frame, **kw):
super(Scrolling_Area, self).__init__(master, **kw)
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self._clipper = Frame(self, background=outer_background, width=width, height=height)
self._clipper.grid(row=0, column=0, sticky=N+E+W+S)
self._width = width
self._height = height
self.innerframe = inner_frame(self._clipper, padx=0, pady=0, highlightthickness=0)
self.innerframe.place(in_=self._clipper, x=0, y=0)
if scroll_vertically:
if yscrollbar is not None:
self.yscrollbar = yscrollbar
else:
self.yscrollbar = Scrollbar(self, orient=VERTICAL)
self.yscrollbar.grid(row=0, column=1,sticky=N+S)
self.yscrollbar.set(0.0, 1.0)
self.yscrollbar.config(command=self.yview)
else:
self.yscrollbar = None
self._scroll_vertically = scroll_vertically
if scroll_horizontally:
if xscrollbar is not None:
self.xscrollbar = xscrollbar
else:
self.xscrollbar = Scrollbar(self, orient=HORIZONTAL)
self.xscrollbar.grid(row=1, column=0, sticky=E+W)
self.xscrollbar.set(0.0, 1.0)
self.xscrollbar.config(command=self.xview)
else:
self.xscrollbar = None
self._scroll_horizontally = scroll_horizontally
self._jfraction=0.05
self._startX = 0
self._startY = 0
# Whenever the clipping window or scrolled frame change size,
# update the scrollbars.
self.innerframe.bind('<Configure>', self._on_configure)
self._clipper.bind('<Configure>', self._on_configure)
self.innerframe.xview = self.xview
self.innerframe.yview = self.yview
Mousewheel_Support(self).add_support_to(self.innerframe, xscrollbar=self.xscrollbar, yscrollbar=self.yscrollbar)
def update_viewport(self):
# compute new height and width
self.update()
frameHeight = float(self.innerframe.winfo_reqheight())
frameWidth = float(self.innerframe.winfo_reqwidth())
if self._width is not None:
width = min(self._width, frameWidth)
else:
width = self._frameWidth
if self._height is not None:
height = min(self._height, frameHeight)
else:
height = self._frameHeight
self._clipper.configure(width=width, height=height)
def _on_configure(self, event):
self._frameHeight = float(self.innerframe.winfo_reqheight())
self._frameWidth = float(self.innerframe.winfo_reqwidth())
# resize the visible part
if self._scroll_horizontally:
self.xview("scroll", 0, "unit")
if self._scroll_vertically:
self.yview("scroll", 0, "unit")
def xview(self, mode = None, value = None, units = None):
value = float(value)
clipperWidth = self._clipper.winfo_width()
frameWidth = self._frameWidth
_startX = self._startX
if mode is None:
return self.xscrollbar.get()
elif mode == 'moveto':
# absolute movement
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
class TreeNode:
def __init__(self, canvas, parent, item, colortheme, vspace=20):
self.canvas = canvas
self.parent = parent
self.item = item
self.state = 'collapsed'
self.selected = False
self.edited = False
self.children = []
self.colortheme =colortheme
self.x = self.y = None
self.vspace=vspace
self.halfvspace=int(round(self.vspace/2))
self.evenodd=0
if not self.parent:
self.canvas.bind('<Configure>',self.reconfig)
def reconfig(self,*args):
if len(self.canvas['scrollregion']) >0:
w,n,e,s = self.canvas._getints(self.canvas['scrollregion'])
if e < self.canvas.winfo_width():
e=self.canvas.winfo_width()
for item in self.canvas.windows:
win,x=item
rightside=x+self.canvas._getints(self.canvas.itemcget(win,'width'))[0]
if rightside<e:
self.canvas.itemconfigure(win,width=e-x)
def destroy(self):
for c in self.children[:]:
self.children.remove(c)
c.destroy()
self.parent = None
def geticonimage(self, name):
return name
def select(self, event=None):
if self.selected:
return
self.deselectall()
self.selected = True
# self.canvas.delete(self.image_id)
self.drawicon()
self.drawtext()
self.item.OnClick()
def deselect(self, event=None):
if not self.selected:
return
self.selected = False
# self.canvas.delete(self.image_id)
self.drawicon()
self.drawtext()
def deselectall(self):
if self.parent:
self.parent.deselectall()
else:
self.deselecttree()
def deselecttree(self):
if self.selected:
self.deselect()
for child in self.children:
child.deselecttree()
def flip(self, event=None):
if self.state == 'expanded':
self.collapse()
else:
self.expand()
self.item.OnDoubleClick()
return "break"
def expand(self, event=None):
if not self.item._IsExpandable():
return
if self.state != 'expanded':
self.state = 'expanded'
self.update()
self.view()
def collapse(self, event=None):
self.deselecttree()
if self.state != 'collapsed':
self.state = 'collapsed'
self.update()
def view(self):
top = self.y
bottom = self.lastvisiblechild().y + self.vspace
height = bottom - top
visible_top = self.canvas.canvasy(0)
visible_height = self.canvas.winfo_height()
visible_bottom = self.canvas.canvasy(visible_height)
if visible_top <= top and bottom <= visible_bottom:
return
x0, y0, x1, y1 = self.canvas._getints(self.canvas['scrollregion'])
#.........这里部分代码省略.........
示例12: Example
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import bind [as 别名]
class Example(Frame):
output_lines = 10
# make debug false when you are actually going to demo this to an audience
debug = 1
def __init__(self, parent):
Frame.__init__(self, parent)
self.hsv_color = colorsys.rgb_to_hsv(0.0, 0.0, 1.0)
self.hex_color = '#0000ff'
# Added second copy of the above two fields for second color
# For debugging, want an initial
if self.debug :
self.hsv_colorTwo = colorsys.rgb_to_hsv(0.0, 0.50, 0.625)
self.hex_colorTwo = '#0088aa'
else:
self.hsv_colorTwo = colorsys.rgb_to_hsv(1.0, 0.0, 0.0)
self.hex_colorTwo = '#ff0000'
self.parent = parent
print "Loading model..."
self.lux = Lux()
self.initUI()
def update_output(self):
(h, s, v) = self.hsv_color
self.cv.set('Color {:.2f} {:.2f} {:.2f} (hsv)'.format(h, s, v))
#tjm Added second update_output method for when second color is chosen
def update_outputTwo(self):
(h, s, v) = self.hsv_colorTwo
self.cvTwo.set('Color {:.2f} {:.2f} {:.2f} (hsv)'.format(h, s, v))
def initUI(self):
row_height = 220
start_height = 30
left_column = 30
sq_size = 180
color_column = left_column
assoc_column = color_column + sq_size + 30
dist_column = assoc_column + 220
y_label = 5
self.parent.title("Interactive LUX visualization")
self.pack(fill=BOTH, expand=1)
self.frame = Frame(self, border=1, relief=SUNKEN, width=sq_size, height=sq_size)
self.frame.place(x=color_column, y=start_height)
self.frame.config(bg=self.hex_color)
self.frame.bind("<Button-1>", self.onChooseClick)
#tjm Added second color display window
self.frameTwo = Frame(self, border=1, relief=SUNKEN, width=sq_size, height=sq_size)
self.frameTwo.place(x=color_column, y=start_height+row_height)
self.frameTwo.config(bg=self.hex_colorTwo)
self.frameTwo.bind("<Button-1>", self.onChooseTwoClick)
#tjm First string field to display the H, S, and V values
self.cv = StringVar()
self.info = Label(self, textvariable=self.cv)
self.info.place(x=color_column, y=y_label)
#tjm second string field to display H, S, and V values
self.cvTwo = StringVar()
self.infoTwo = Label(self, textvariable=self.cvTwo)
self.infoTwo.place(x=color_column, y=y_label+row_height)
#tjm label for associated color terms field
self.cvThree = StringVar()
self.infoThree = Label(self, textvariable=self.cvThree)
self.infoThree.place(x=assoc_column, y=y_label)
#tjm label for distinguishing color terms field
self.cvFour = StringVar()
self.infoFour = Label(self, textvariable=self.cvFour)
self.infoFour.place(x=dist_column, y=y_label)
#tjm instruction text for color term assignment prediction function
self.cvFive = StringVar()
self.infoFive = Label(self, textvariable=self.cvFive)
self.infoFive.place(x=left_column, y=y_label+2*row_height)
self.display = Text(self, border=1,
relief=SUNKEN, width=25, height=self.output_lines)
self.display.place(x=assoc_column, y=start_height)
self.display.tag_configure('undistinguished', foreground='dark salmon')
#tjm Added second text window to display color labels
self.displayTwo = Text(self, border=1,
relief=SUNKEN, width=25, height=self.output_lines)
self.displayTwo.place(x=assoc_column, y=start_height+row_height)
self.displayTwo.tag_configure('undistinguished', foreground='dark salmon')
#tjm Text field that displays distinction color term for top color
self.distLabel = Text(self, border=1,
relief=SUNKEN, width=25, height=self.output_lines)
self.distLabel.place(x=dist_column, y=start_height)
#.........这里部分代码省略.........