本文整理汇总了Python中tkinter.Label.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Label.bind方法的具体用法?Python Label.bind怎么用?Python Label.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Label
的用法示例。
在下文中一共展示了Label.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initUI
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label 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)
示例2: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
class MyFirstGUI:
LABEL_TEXT = [
"This is our first GUI!",
"Actually, this is our second GUI.",
"We made it more interesting...",
"...by making this label interactive.",
"Go on, click on it again.",
]
def __init__(self, master):
self.master = master
master.title("A simple GUI")
self.label_index = 0
self.label_text = StringVar()
self.label_text.set(self.LABEL_TEXT[self.label_index])
self.label = Label(master, textvariable=self.label_text)
self.label.bind("<Button-1>", self.cycle_label_text)
self.label.pack()
self.greet_button = Button(master, text="Greet", command=self.greet)
self.greet_button.pack()
self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()
def greet(self):
print("Greetings!")
def cycle_label_text(self, event):
self.label_index += 1
self.label_index %= len(self.LABEL_TEXT) # wrap around
self.label_text.set(self.LABEL_TEXT[self.label_index])
示例3: __makeWidgets
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
def __makeWidgets(self):
Label(self, text="Welcome to PyMath 0.3!\n", justify="center").pack()
Label(self, text="Use the tabs to navigate between PyMath's different functions.", justify="center").pack()
l = Label(self, text="About/Help", fg="blue", padx=10, pady=10)
l.pack(side=BOTTOM, anchor=SE)
l.config(cursor="hand2")
l.bind("<Button-1>", self.showabout)
示例4: show_about
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
def show_about(self):
about = About(self.master, "About {}".format(self.version[:-5]), self.logo)
Label(about.frame, text=self.version, style="atitle.TLabel").grid(sticky="w")
Label(about.frame, text="Developer: Joel W. Dafoe").grid(pady="6", sticky="w")
link = Link(about.frame, text="http://cyberdatx.com", foreground="blue", cursor="hand2")
link.grid(sticky="w")
link.bind("<Button-1>", lambda e: webbrowser.open("http://cyberdatx.com"))
Label(about.frame, text=self.description, wraplength=292).grid(columnspan=2, pady=6, sticky=W)
示例5: LoginGui
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
class LoginGui(object):
def __init__(self, root):
self.welcome_text = 'Prihlaseny' if User.is_loaded_session() else ""
self.response_text = StringVar(root, value=self.welcome_text)
self.top_frame = Frame(root, width=400, height=400)
self.middle_frame = Frame(root, width=300, height=300)
self.top_frame.pack(fill="both", expand=True, padx=20, pady=20)
self.middle_frame.place(in_=self.top_frame, anchor='c', relx=.5, rely=.5)
self.l_email = Label(self.middle_frame, text="Email")
self.e_email = Entry(self.middle_frame)
self.l_pass = Label(self.middle_frame, text="Password")
self.e_pass = Entry(self.middle_frame, show="*")
self.l_sign_up = Label(self.middle_frame, text="Sign up", fg='blue', cursor='hand2')
self.l_req_result = Label(self.middle_frame, textvariable=self.response_text)
self.b_submit = Button(self.middle_frame, text="Login")
self.l_email.grid(row=0, sticky=E)
self.e_email.grid(row=0, column=1)
self.l_pass.grid(row=1, column=0, sticky=E)
self.e_pass.grid(row=1, column=1)
self.b_submit.grid(row=2, column=1, sticky=E)
self.l_sign_up.grid(row=3, column=1, sticky=E)
self.l_req_result.grid(row=4)
self.l_sign_up.bind('<Button-1>', self.sing_up_callback)
self.b_submit.bind('<Button-1>', self.login)
self.root = root
self.root.mainloop()
def login(self, event):
response = User.login(self.e_email.get(), self.e_pass.get())
self.response_text.set(response)
if User.is_loaded_session():
self.root.destroy()
@staticmethod
def sing_up_callback(event):
webbrowser.open_new(Config.SIGN_UP_URL)
@staticmethod
def show_login():
root = tkinter.Tk(className="Productivity optimizer")
LoginGui(root)
root.mainloop()
示例6: show_about
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
def show_about(self):
about = Toplevel(self.master)
about.title('About {}'.format(self.version[:-5]))
about.focus()
about.resizable(0, 0)
logo_lbl = Label(about, image=self.logo)
logo_lbl.image = self.logo
logo_lbl.grid(row=0, column=0, padx='7 11', pady=13, sticky='n')
about_frame = Frame(about, padding='0 10 10 10')
about_frame.grid(row=0, column=1)
Label(about_frame, text=self.version).grid(sticky='w')
Label(about_frame, text='Developer: Joel W. Dafoe').grid(pady='6', sticky='w')
link = Link(about_frame, text='http://cyberdatx.com', foreground='blue', cursor='hand2')
link.grid(sticky='w')
link.bind('<Button-1>', lambda e: webbrowser.open('http://cyberdatx.com'))
Label(about_frame, text=self.description, wraplength=292).grid(columnspan=2, pady=6, sticky='w')
cls_btn = Button(about_frame, text='OK', command=about.destroy)
cls_btn.grid(column=1, sticky='e')
cls_btn.focus()
about.bind('<Return>', lambda e: cls_btn.invoke())
示例7: append_chords
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
def append_chords(self, chords=[]):
'''pass a [list] of Chords to the Accordion object'''
self.update_idletasks()
row = 0
width = max([c.winfo_reqwidth() for c in chords])
for c in chords:
i = PhotoImage() # blank image to force Label to use pixel size
label = Label(self, text=c.title,
image=i,
compound='center',
width=width,
anchor='w',
font=('Franklin Gothic Book', 11),
bg=self.style['title_bg'],
fg=self.style['title_fg'],
cursor=self.style['cursor'],
bd=1, relief='flat')
label.grid(row=row, column=0, sticky='nsew')
c.grid(row=row+1, column=0, sticky='nsew')
c.grid_remove()
row += 2
label.bind('<Button-1>', lambda e,
c=c: self._click_handler(c))
label.bind('<Enter>', lambda e,
label=label, i=i: label.configure(bg=self.style['highlight'],fg=self.style['highlight_fg']))
label.bind('<Leave>', lambda e,
label=label, i=i: label.configure(bg=self.style['title_bg'],fg=self.style['title_fg']))
示例8: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
class Photo:
def __init__(self, **kwargs):
self.repr = kwargs['repr']
self.path = kwargs['path']
def config(self, **kwargs):
if 'path' in kwargs:
self.path = kwargs['path']
self.picture = Image.open(self.path)
self.picture = self.picture.resize((200, 200), Image.ANTIALIAS)
self.image = ImageTk.PhotoImage(self.picture)
self.label.config(image=self.image)
def place(self, **kwargs):
self.parent = kwargs['parent']
self.row = kwargs['row']
self.column = kwargs['column']
self.picture = Image.open(self.path)
self.image = ImageTk.PhotoImage(self.picture)
self.label = Label(self.parent, image=self.image, bd=1)
self.label.grid(row=self.row, column=self.column)
self.label.bind('<Button-1>', lambda e: self.label.focus_set())
def getData(self):
return self.path
def setData(self, data):
#le sigh
if data == '' or 'N/A': return
self.config(path=data)
def hide(self):
self.label.grid_forget()
示例9: Play
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
class Play():
def StartGame(self,minesAmount,height,width):
blockWidth=50
blockHeight=50
self.minesAmount=minesAmount
'''function called when we press play'''
self.gameEngine=GE(minesAmount,height,width)
self.playWindow=Tk()
self.playWindow.geometry(str(blockWidth*width+blockWidth//2)+'x'+str(blockHeight*height+blockHeight//2)+'+200+200')
self.playWindow.title("Minesweeper")
self.playFrame=PF(self.playWindow,height,width,blockHeight,blockWidth)
self.playFrame.canvas.bind("<Button-1>", self.leftClick)
self.playFrame.canvas.bind("<Button-3>", self.rightClick)
self.playFrame.pack()
self.alive=True
self.update()
def leftClick(self,event):
if self.alive:
x=event.x//50
y=event.y//50
self.alive=self.gameEngine.ExposeBlock(x,y)
self.update()
else:
self.DeadFrame()
def rightClick(self,event):
if self.alive:
x=event.x//50
y=event.y//50
self.gameEngine.ManageFlags(x,y)
self.update()
def update(self):
shownField,activeMines=self.gameEngine.GetStatus()
self.playFrame.Paint(activeMines,shownField)
self.checkWin(shownField)
def checkWin(self,shownField):
if self.alive:
currentBlocks=sum([1 for x in shownField if x=='X' or x=='F'])
if currentBlocks==self.minesAmount:
self.WinFrame()
def DeadFrame(self):
self.playFrame.destroy()
self.deadScreen=Frame(self.playWindow,bg="red")
self.deadScreen.pack(fill="both", expand=1)
self.deadText=Label(self.deadScreen,text="You stepped on a mine!\nClick here to try again.",fg="black",bg="red")
self.deadText.bind("<Button-1>",self.onClickRestart)
self.deadText.pack()
def WinFrame(self):
self.playFrame.destroy()
self.winScreen=Frame(self.playWindow,bg="blue")
self.winScreen.pack(fill="both", expand=1)
self.winText=Label(self.winScreen,text="You won!\nClick here to try again.",fg="yellow",bg="blue")
self.winText.bind("<Button-1>",self.onClickRestart)
self.winText.pack()
def onClickRestart(self,event):
self.playWindow.destroy()
main=MainMenu()
main.main()
示例10: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
def __init__(self, master, columns, column_weights=None, cnf={}, **kw):
"""
Construct a new multi-column listbox widget.
:param master: The widget that should contain the new
multi-column listbox.
:param columns: Specifies what columns should be included in
the new multi-column listbox. If ``columns`` is an integer,
the it is the number of columns to include. If it is
a list, then its length indicates the number of columns
to include; and each element of the list will be used as
a label for the corresponding column.
:param cnf, kw: Configuration parameters for this widget.
Use ``label_*`` to configure all labels; and ``listbox_*``
to configure all listboxes. E.g.:
>>> mlb = MultiListbox(master, 5, label_foreground='red')
"""
# If columns was specified as an int, convert it to a list.
if isinstance(columns, int):
columns = list(range(columns))
include_labels = False
else:
include_labels = True
if len(columns) == 0:
raise ValueError("Expected at least one column")
# Instance variables
self._column_names = tuple(columns)
self._listboxes = []
self._labels = []
# Pick a default value for column_weights, if none was specified.
if column_weights is None:
column_weights = [1] * len(columns)
elif len(column_weights) != len(columns):
raise ValueError('Expected one column_weight for each column')
self._column_weights = column_weights
# Configure our widgets.
Frame.__init__(self, master, **self.FRAME_CONFIG)
self.grid_rowconfigure(1, weight=1)
for i, label in enumerate(self._column_names):
self.grid_columnconfigure(i, weight=column_weights[i])
# Create a label for the column
if include_labels:
l = Label(self, text=label, **self.LABEL_CONFIG)
self._labels.append(l)
l.grid(column=i, row=0, sticky='news', padx=0, pady=0)
l.column_index = i
# Create a listbox for the column
lb = Listbox(self, **self.LISTBOX_CONFIG)
self._listboxes.append(lb)
lb.grid(column=i, row=1, sticky='news', padx=0, pady=0)
lb.column_index = i
# Clicking or dragging selects:
lb.bind('<Button-1>', self._select)
lb.bind('<B1-Motion>', self._select)
# Scroll whell scrolls:
lb.bind('<Button-4>', lambda e: self._scroll(-1))
lb.bind('<Button-5>', lambda e: self._scroll(+1))
lb.bind('<MouseWheel>', lambda e: self._scroll(e.delta))
# Button 2 can be used to scan:
lb.bind('<Button-2>', lambda e: self.scan_mark(e.x, e.y))
lb.bind('<B2-Motion>', lambda e: self.scan_dragto(e.x, e.y))
# Dragging outside the window has no effect (diable
# the default listbox behavior, which scrolls):
lb.bind('<B1-Leave>', lambda e: 'break')
# Columns can be resized by dragging them:
l.bind('<Button-1>', self._resize_column)
# Columns can be resized by dragging them. (This binding is
# used if they click on the grid between columns:)
self.bind('<Button-1>', self._resize_column)
# Set up key bindings for the widget:
self.bind('<Up>', lambda e: self.select(delta=-1))
self.bind('<Down>', lambda e: self.select(delta=1))
self.bind('<Prior>', lambda e: self.select(delta=-self._pagesize()))
self.bind('<Next>', lambda e: self.select(delta=self._pagesize()))
# Configuration customizations
self.configure(cnf, **kw)
示例11: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
#.........这里部分代码省略.........
# put buttons for GOTO and MOVE
self.butGotoLow = Button(self.fr, text="Go To Low",
justify='center', bg=buttoncolor, command=self.gotoLow)
self.butGotoLow.grid(row=10, column=0, sticky='we')
self.butGotoHi = Button(self.fr, text="Go To High",
justify='center', bg=buttoncolor, command=self.gotoHi)
self.butGotoHi.grid(row=10, column=1, sticky='we')
self.butMoveStep = Button(self.fr, text="Move a Step",
justify='center', bg=buttoncolor, command=self.moveStep)
self.butMoveStep.grid(row=10, column=2, sticky='we')
self.emptyRow(11)
Label(self.fr, text='EXTERNAL SENSORS', justify='left',
anchor='w', bg=bgcolor, fg=statuscolor, font=("Calibri", 12)
).grid(row=12, column=0, columnspan=3, sticky='we', padx=(5, 0))
# function buttons
# RIadok 13-16: Externals
# Interferometer
buttonIfm = Button(self.fr, text="Read IFM", width=15, justify='center',
bg=buttoncolor, command=self.getIfm) # self.exit_root)
buttonIfm.grid(row=13, column=0, sticky='we')
self.labelIfmStatus = Label(self.fr, textvariable=self.ifmStatus,
justify='left', anchor='w', bg=bgcolor, fg=statuscolor,
font=("Calibri", 12))
self.labelIfmStatus.grid(row=13, column=1, columnspan=2,
sticky='we', padx=(15, 0))
self.labelIfmStatus.bind('<Button-1>', self.resetIfmStatus)
# Digital level (Leica /Trimble)
buttonLevel = Button(self.fr, text="Read Level", width=15, justify='center',
bg=buttoncolor, command=self.getLevel) # self.exit_root)
buttonLevel.grid(row=14, column=0, sticky='we')
self.labelLevelStatus = Label(self.fr, textvariable=self.levelStatus,
justify='left', anchor='w', bg=bgcolor, fg=statuscolor,
font=("Calibri", 12))
self.labelLevelStatus.grid(row=14, column=1, columnspan=2,
sticky='we', padx=(15, 0))
self.labelLevelStatus.bind('<Button-1>', self.resetLevelStatus)
# Nivel - inclinometer
buttonNivel = Button(self.fr, text="Read Nivel", width=15, justify='center',
bg=buttoncolor, command=self.getNivel) # self.exit_root)
buttonNivel.grid(row=15, column=0, sticky='we')
self.labelNivelStatus = Label(self.fr, textvariable=self.nivelStatus,
justify='left', anchor='w', bg=bgcolor, fg=statuscolor,
font=("Calibri", 12))
self.labelNivelStatus.grid(row=15, column=1, columnspan=2,
sticky='we', padx=(15, 0))
self.labelNivelStatus.bind('<Button-1>', self.resetNivelStatus)
# Thermometer line
buttonThermo = Button(self.fr, text="Read Thermo", width=15, justify='center',
bg=buttoncolor, command=self.getThermo) # self.exit_root)
buttonThermo.grid(row=16, column=0, sticky='we')
self.labelThermoStatus = Label(self.fr, textvariable=self.thermoStatus,
justify='left', anchor='w', bg=bgcolor, fg=statuscolor,
示例12: mainGUI
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
class mainGUI(Frame, bootloader, GuiController):
""" Contains the main view for the application """
def __init__(self):
""" Create the initial application GUI environment (tool bars, and other static elements) """
Frame.__init__(self, self.root)
self.thread_entry_field = '' # Hold both search string, and drives autoRefresh logic
self.menuBar = Menu()
self.fileMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="File", menu=self.fileMenu, underline=1)
self.fileMenu.add_command(label="Quit", command=self.root.destroy, underline=1)
self.optionsMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="Options", menu=self.optionsMenu)
self.optionsMenu.add_command(label="Settings", command=self.editSettings, underline=1)
self.helpMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="Help", menu=self.helpMenu)
self.helpMenu.add_command(label="Help", command=self.program_help, underline=1)
self.helpMenu.add_command(label="About", command=self.program_about, underline=1)
self.master.config(menu=self.menuBar)
self.topFrame = Frame()
self.thread_entry_box = Entry(self.topFrame)
self.thread_entry_box.insert(0, self.DEFAULT_THREAD_TEXT)
self.thread_entry_box.bind('<Return>', lambda event: self.add_thread_GUI())
# Bind needs to send the event to the handler
self.thread_entry_box.pack(side='left', fill='x', expand='True', padx=5)
self.add_thread_btn = Button(self.topFrame)
self.add_thread_btn['text'] = 'Add New Thread'
self.add_thread_btn['command'] = lambda: self.add_thread_GUI()
self.add_thread_btn.pack(side='left', padx=0)
self.topFrame.pack(fill='x')
self.create_thread_frame()
def create_thread_frame(self):
""" Sets up the main thread frame (where the magic happens) """
# Sets up frame
self.thread_list_canvas = Canvas(self.root, borderwidth=0)
self.thread_list_frame = Frame(self.thread_list_canvas)
# Creates scroll bar
self.vsb = Scrollbar(self.root, orient="vertical", command=self.thread_list_canvas.yview)
self.thread_list_canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.hsb = Scrollbar(self.root, orient="horizontal", command=self.thread_list_canvas.xview)
self.thread_list_canvas.configure(xscrollcommand=self.hsb.set)
self.hsb.pack(side="bottom", fill="x")
# Packs frame
self.thread_list_canvas.pack(side="left", fill="both", expand=True)
self.thread_list_canvas.create_window((4, 4), window=self.thread_list_frame, anchor="nw", tags="self.frame")
self.thread_list_frame.bind("<Configure>", self.OnFrameConfigure)
self.create_thread_list_box()
def OnFrameConfigure(self, event):
"""Reset the scroll region to encompass the inner frame"""
self.thread_list_canvas.configure(scrollregion=self.thread_list_canvas.bbox("all"))
# noinspection PyAttributeOutsideInit
def create_thread_list_box(self):
""" Creates the message list box for the create method """
def hover_on(widget):
widget['fg'] = 'dark blue'
# widget['underline'] = True
def hover_off(widget):
widget['fg'] = 'black'
# widget['underline'] = False
for individual_thread in self.MESSAGE_THREADS: # Fetch Message List from model
if individual_thread.is_valid_thread():
self.bg_color = 'green'
else:
self.bg_color = 'red'
self.individual_thread_frame = Frame(self.thread_list_frame,
bg=self.bg_color) # Create frame for each thread
rowToInsertAt = self.MESSAGE_THREADS.index(individual_thread)
self.text_color = 'black'
self.threadText = Label(self.individual_thread_frame, bg=self.bg_color, fg=self.text_color)
self.threadText['text'] = "[ Thread #: " + individual_thread.threadId + " ]"
self.threadText.bind("<Enter>", lambda event, text=self.threadText: hover_on(text))
self.threadText.bind("<Leave>", lambda event, text=self.threadText: hover_off(text))
self.threadText.bind("<Button-1>",
lambda event, thread_in=individual_thread: self.open_in_web_browser(thread_in))
self.threadText.grid(column=0, row=0, sticky='w', padx=0)
#.........这里部分代码省略.........
示例13: Photo
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
class Photo(Widget):
def __init__(self, **kwargs):
try:
self.repr = kwargs['repr']
self.path = kwargs['path']
except:
print("widget could not be loaded")
#self.script_dir = os.path.dirname(os.path.abspath(__file__))
self.width = 200
self.height = 200
def config(self, **kwargs):
try:
self.path = kwargs['path']
self.picture = Image.open(self.path)
if 'resize_portr' in kwargs:
self.picture = self.picture.resize((200, 200), Image.ANTIALIAS)
self.image = ImageTk.PhotoImage(self.picture)
self.label.config(image=self.image)
except:
pass
#print("the widget could not be configured")
try:
self.bgc = kwargs['bg']
self.label.config(bg=self.bgc)
except:
pass
#print("the widget background color could not be changed")
def trytoplace(self, **kwargs):
self.parent = kwargs['parent']
self.row = kwargs['row']
self.column = kwargs['column']
def place(self, **kwargs):
try:
self.trytoplace(**kwargs)
except:
print("widget could not be placed")
self.picture = Image.open(self.path)
self.image = ImageTk.PhotoImage(self.picture)
self.label = Label(self.parent, image=self.image, bd=1)#, bg='black')
self.label.grid(row=self.row, column=self.column, pady=5)
self.label.bind('<Button-1>', lambda e: self.label.focus_set())
def getData(self):
return self.path
def setData(self, data):
#le sigh
if data == '' or 'N/A': return
self.config(path=data, resize_portr=True)
def hide(self):
self.label.grid_forget()
示例14: Frontend
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
class Frontend():
def __init__(self,x,y,b):
self.x=str(x) #1600
self.y=str(y) #900
self.pressed=0
self.b=10
self.c=30
self.grapher=0
self.graph=[0,0,0,0]
self.root=b
def startwindow(self):
# self.root=Tk()
a=str(self.x+'x'+self.y)
self.root.title('Wahrscheinlichkeinten & Simulation')
self.root.geometry(a)
self.g=Label(self.root,bg='white')
self.g.place(x=0,y=0,width=self.x,height=self.y)
# self.g.bind('<1>',self.optioncanged)
self.lst1 = ['Marriage','Atom','BubbleGum','House_of_Cards','Lotto','SecretSanta','Coins']
self.var1 = StringVar(self.root)
self.var1.set('Marriage')
self.drop = OptionMenu(self.root,self.var1,*self.lst1)
self.drop.config(font=('Arial',(30)),bg='white')
self.drop['menu'].config(font=('calibri',(20)),bg='white')
self.drop.pack(side=TOP)
self.photo = PhotoImage(file='z1.gif')
self.label = Label(image=self.photo,borderwidth=0)
self.label.image = self.photo
self.label.bind('<1>',self.MouseOneDown)
self.label.place(y=0,x=int(self.x)-200)
self.startbutton=Button(self.root,text='Start',font=('Arial',40),bg='#B4045F',borderwidth=5,command=self.startpressed)
self.startbutton.place(x=0,y=int(self.y)-100,width=int(self.y)-200,height=100)
self.csvbutton=Button(self.root,text='Export CSV',font=('Arial',40),bg='green',borderwidth=5,command=self.csvpressed)
self.csvbutton.place(x=int(self.x)/2+50,y=int(self.y)-100,width=int(self.y)-230,height=100)
def startpressed(self):
if self.grapher==1:
for x in range(len(self.graph)):
if self.graph[x]!=0:
self.graph[x].destroy()
self.grapher=0
self.root.update()
a=self.var1.get()
if self.pressed==1:
try:
self.b=int(self.changer0.get('1.0','end-1c'))
except (AttributeError,TclError,ValueError):
self.b=10
try:
self.c=self.changer2.get('1.0','end-1c')
except (AttributeError,TclError,ValueError):
self.c=1
if a=='Marriage':
self.run0=Marriage(self.b)
self.run0.DEBUG=False
self.run0.sim()
elif a=='Atom':
self.c=float(self.c)
self.run1=Atom(self.c,self.b)
self.run1.DEBUG=False
self.run1.sim()
elif a=='BubbleGum':
self.run2=BubbleGum(self.b)
self.run2.DEBUG=False
self.run2.sim()
self.grapher=1
self.graph=[0,0]
g=str(round(self.run2.getrel()[0],4))
h=str(round(self.run2.getrel()[1],4))
self.graph[0]=Label(self.root,bg='white',text='Durchschnitt Karten zu viel: '+g,font=('calibri',19))
self.graph[0].place(x=10,y=450)
self.graph[1]=Label(self.root,bg='white',text='Durchschnitt dass es passiert: '+h,font=('calibri',19))
self.graph[1].place(x=10,y=500)
elif a=='House_of_Cards':
if self.c=='':
self.c=0
else:
self.c=int(self.c)
self.run3=House_of_Cards(self.b,self.c)
self.run3.DEBUG=False
self.run3.sim()
self.grapher=1
self.graph=[0]
self.graph[0]=Label(self.root,bg='white',text=('Durchschnitt: '+str(round(self.run3.getrel(),4))),font=('calibri',19))
self.graph[0].place(x=10,y=450)
elif a=='Lotto':
self.run4=Lotto(self.b)
self.run4.DEBUG=False
self.run4.sim()
x=4
y=1
count=0
self.graph=[0,0,0,0]
self.grapher=1
self.graph[0]=Label(self.root,bg='black')
self.graph[0].place(x=10,width=10+(int(self.x)*0.8),height=1,y=int(self.y)-int(self.y)/4*0.5-350)
self.graph[1]=Label(self.root,text='50%',bg='white',font=('calibri',10))
self.graph[1].place(x=60+(int(self.x)*0.8),width=50,height=50,y=int(self.y)-int(self.y)/4*0.5-375)
self.graph[2]=Label(self.root,bg='black')
self.graph[2].place(x=10,width=20,height=1,y=int(self.y)-350)
self.graph[3]=Label(self.root,bg='black')
#.........这里部分代码省略.........
示例15: view_details
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import bind [as 别名]
def view_details(self, Medikom, id):
self.selected_id = id
self.overview(Medikom)
entry_results, attachments = Medikom.get_entry(id)
ts, title, notes = entry_results
ts = self.format_ts(ts)[:-3]
details_text = 'Details zu %s (zuletzt geändert am %s)' % (title, ts)
details_label = Label(
self, text=details_text, font='Liberation 10', fg='Black', anchor='w')
details_label.place(
x=self.SPACE_TWO,
y=(self.n + 2) * (self.ROW_HIGHT + self.ROW_SPACE),
width=self.WIN_WIDTH - self.SPACE_TWO, height=self.ROW_HIGHT)
details_label.bind(sequence='<Button-1>',
func=Callable(self.view_edit_title, Medikom, id, title))
# add attachment button and list attachments
attach_button = Button(
self, text='Neuer Anhang',
command=lambda: self.attach_file(Medikom, id))
attach_button.place(
x=self.SPACE_TWO,
y=(self.n + 3) * (self.ROW_HIGHT + self.ROW_SPACE),
width=self.WIN_WIDTH / 8, height=self.ROW_HIGHT)
if attachments:
xpos = (1.5 * self.SPACE_TWO) + (self.WIN_WIDTH / 8)
for i, attachment in enumerate(attachments):
attachment = attachment[0]
filename = ''
if '\\' in attachment:
filename = attachment.split('\\')[-1]
elif '/' in attachment:
filename = attachment.split('/')[-1]
width = len(filename) * 7.2
attachment_button = Button(
self, text=filename, font='Courier 9', fg="blue",
command=Callable(self.open_attachment, attachment))
attachment_button.place(
x=xpos,
y=(self.n + 3) * (self.ROW_HIGHT + self.ROW_SPACE),
width=width, height=self.ROW_HIGHT)
xpos = xpos + width + (self.SPACE_TWO/2)
attachment_button.config(relief='flat')
attachment_button.bind(sequence='<Button-3>',
func=Callable(self.unattach_file, Medikom, id, attachment))
# text element and scrollbar
textframe = Text(
self, font='Liberation 12', height=self.TEXT_FRAME_LINES,
width=int(self.WIN_WIDTH / 4))
scrollbar = Scrollbar(self)
textframe.place(
x=self.SPACE_TWO,
y=(self.n + 4) * (self.ROW_HIGHT + self.ROW_SPACE),
width=self.WIN_WIDTH - self.SPACE_ONE - 10,
height=self.ROW_HIGHT * self.TEXT_FRAME_LINES)
scrollbar.place(
x=self.SPACE_TWO + self.WIN_WIDTH - self.SPACE_ONE - 10,
y=(self.n + 4) * (self.ROW_HIGHT + self.ROW_SPACE),
width=10,
height=self.ROW_HIGHT * self.TEXT_FRAME_LINES)
scrollbar.config(command=textframe.yview)
textframe.config(yscrollcommand=scrollbar.set)
textframe.insert(END, notes)
# update button
update_button = Button(
self, text='Text Aktualisieren',
command=lambda: self.update_entry_notes(
Medikom, id, textframe.get(1.0, END)))
update_button.place(
x=self.WIN_WIDTH / 2 - 0.125 * self.WIN_WIDTH,
y=(self.n + 4) * (self.ROW_HIGHT + self.ROW_SPACE) + (self.ROW_HIGHT * self.TEXT_FRAME_LINES + 5),
width=self.WIN_WIDTH/4, height=self.ROW_HIGHT)