本文整理汇总了Python中tkinter.Label.configure方法的典型用法代码示例。如果您正苦于以下问题:Python Label.configure方法的具体用法?Python Label.configure怎么用?Python Label.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Label
的用法示例。
在下文中一共展示了Label.configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: append_chords
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [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']))
示例2: Channel
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class Channel(Frame):
"""
Stuff a channel tracks:
- The track number
- Recording
- Active
- Muted
- Sticky
- Non-empty
"""
def __init__(self, parent, trackNumber):
Frame.__init__(self, parent, relief = RAISED, borderwidth = 3,
background = 'black')
self.channel = trackNumber
self.record = False
self.nonEmpty = False
self.active = False
self.sticky = False
self.label = Label(self)
self.label.pack()
self.__updateStatus()
self.configure(relief = RAISED)
def __updateStatus(self):
# First and last characters are brackets for the active track.
# Second character is 'R' for recording, 'P' for playing and ' ' for
# empty. Third character is '*' for sticky, ' ' if not.
self.label.configure(text = '%d: %s%s%s%s' % (
self.channel,
self.active and '[' or ' ',
self.record and 'R' or
self.nonEmpty and 'P' or
' ',
self.sticky and '*' or ' ',
self.active and ']' or ' '
))
def changeStatus(self, status):
self.nonEmpty = status & NONEMPTY
self.record = status & RECORD
self.sticky = status & STICKY
self.active = status & ACTIVE
print('changing status of %d, nonempty = %s, record = %s, '
'sticky = %s, active = %s' % (self.channel, self.nonEmpty,
self.record, self.sticky,
self.active))
self.__updateStatus()
示例3: AddManually
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class AddManually(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
self.place(relx=0.0, rely=0.0, relheight=0.62, relwidth=0.72)
self.configure(relief=GROOVE)
self.configure(borderwidth="2")
self.configure(relief=GROOVE)
self.configure(width=125)
self.label_top = Label(self)
self.label_top.place(relx=0.4, rely=0.03, height=21, width=112)
self.label_top.configure(text="Add items manually")
self.name = Entry(self, fg='grey')
self.name.place(relx=0.05, rely=0.31, relheight=0.08, relwidth=0.29)
self.name.insert(0, "Input name here")
self.name.bind('<Button-1>', lambda event: greytext(self.name))
self.link = Entry(self, fg='grey')
self.link.place(relx=0.65, rely=0.31, relheight=0.08, relwidth=0.29)
self.link.insert(0, "Input link here")
self.link.bind('<Button-1>', lambda event: greytext(self.link))
self.add_btn = Button(self, command=self.send_data)
self.add_btn.place(relx=0.42, rely=0.44, height=34, width=100)
self.add_btn.configure(text="Add item")
self.back = Button(self, command=lambda: controller.show_frame('Main'))
self.back.place(relx=0.42, rely=0.64, height=34, width=100)
self.back.configure(text="Go back")
name_label = Label(self)
name_label.place(relx=0.05, rely=0.22, height=21, width=38)
name_label.configure(text="Name")
link_label = Label(self)
link_label.place(relx=0.65, rely=0.22, height=21, width=28)
link_label.configure(text="Link")
def send_data(self):
if self.link.cget('fg') == 'grey' or self.name.cget('fg') == 'grey':
return
link = self.link.get()
if link.strip() != '':
name = self.name.get()
self.controller.add_item(link, name)
print("Item added")
示例4: ControlWidget
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class ControlWidget(Frame):
'''Control widget class.'''
def __init__(self, parent, handler):
'''Initialization method.'''
Frame.__init__(self, parent)
button_frame = Frame(self)
button_frame.pack(side=TOP)
self.deal_button = Button(button_frame, text="Deal",
command=lambda: handler("deal"))
self.deal_button.pack(side=LEFT, padx=5, pady=5)
self.quit_button = Button(button_frame, text="Quit",
command=lambda: handler("quit"))
self.quit_button.pack(side=RIGHT, padx=5, pady=5)
self.exchange_button = Button(button_frame, text="Exchange",
command=lambda: handler("exchange"))
self.exchange_button.pack(side=RIGHT, padx=5, pady=5)
self.show_button = Button(button_frame, text="Show",
command=lambda: handler("show"))
self.show_button.pack(side=RIGHT, padx=5, pady=5)
label_frame = Frame(self)
label_frame.pack(side=BOTTOM)
self.status_label = Label(label_frame, relief=SUNKEN)
self.set_status_text("No text to show")
self.status_label.pack(side=TOP, padx=5, pady=5)
def set_status_text(self, text):
'''Sets the text of the status label.'''
self.status_label.configure(text=text)
示例5: PreferenceRanking
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class PreferenceRanking(ttk.Frame):
"""Allows a DM to be selected and displays that DMs state ranking."""
def __init__(self, master, conflict, dm, idx):
"""Initialize a PreferenceRanking widget."""
ttk.Frame.__init__(self, master, borderwidth=2)
self.conflict = conflict
self.dm = dm
self.dmIdx = idx
self.dmText = StringVar(value=dm.name + ': ')
self.dmLabel = Label(self, textvariable=self.dmText)
self.dmLabel.grid(row=0, column=0, sticky=NSEW)
if len(conflict.feasibles) < 1000:
self.prefRankText = StringVar(value=str(dm.perceivedRanking))
else:
self.prefRankText = StringVar(value="Too Many States")
self.prefRank = ttk.Label(self, textvariable=self.prefRankText,
relief="sunken", width=40)
self.prefRank.grid(row=1, column=0, sticky=NSEW)
self.selectBtn = ttk.Button(self, text="Edit", command=self.selectCmd)
self.selectBtn.grid(row=0, column=1, rowspan=2, sticky=NSEW)
self.columnconfigure(0, weight=1)
def selectCmd(self, *args):
"""Propagate a selection event up to the parent widget."""
self.event_generate('<<DMselect>>', x=self.dmIdx)
def deselect(self, *args):
"""Change the widget to the deselected state."""
self.configure(relief='flat')
self.dmLabel.configure(bg="SystemButtonFace")
def select(self, *args):
"""Change the widget to the selected state."""
self.configure(relief='raised')
self.dmLabel.configure(bg="green")
示例6: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
#.........这里部分代码省略.........
self.rsm_normal_lower_label.place(x=5, y=65, height=25, width=200)
self.rsm_parallel_upper_label.place(x=5, y=95, height=25, width=200)
self.rsm_normal_upper_label.place(x=5, y=125, height=25, width=200)
self.rsm_parallel_lower_entry.place(x=210, y=35, height=25, width=200)
self.rsm_parallel_upper_entry.place(x=210, y=65, height=25, width=200)
self.rsm_normal_lower_entry.place(x=210, y=95, height=25, width=200)
self.rsm_normal_upper_entry.place(x=210, y=125, height=25, width=200)
self.rsm_sclae_linear.place(x=5, y=155, height=25, width=200)
self.rsm_sclae_log.place(x=210, y=155, height=25, width=200)
self.create_rsm_button.place(x=5, y=185, height=25, width=405)
self.linescan_frame.place(x=5, y=260, width=415, height=220)
self.linescan_label.place(x=5, y=5, width=405, height=25)
self.origin_parallel_label.place(x=5, y=35, width=200, height=25)
self.origin_normal_label.place(x=5, y=65, width=200, height=25)
self.linescan_angle_label.place(x=5, y=95, width=200, height=25)
self.linescan_width_label.place(x=5, y=125, width=200, height=25)
self.origin_parallel_entry.place(x=210, y=35, width=200, height=25)
self.origin_normal_entry.place(x=210, y=65, width=200, height=25)
self.linescan_angle_entry.place(x=210, y=95, width=200, height=25)
self.linescan_width_entry.place(x=210, y=125, width=200, height=25)
self.line_scale_linear.place(x=5, y=155, width=200, height=25)
self.line_scale_log.place(x=210, y=155, width=200, height=25)
self.create_linescan_button.place(x=5, y=185, width=405, height=25)
self.rsm_plot_frame.place(x=440, y=10, width=480, height=520)
self.rsm_canvas.get_tk_widget().place(x=5, y=5, height=470, width=470)
self.linescan_plot_frame.place(x=925, y=10, width=480, height=520)
self.linescan_canvas.get_tk_widget().place(x=5, y=5, height=470, width=470)
def select_file(self):
self.file_path = askopenfilename()
self.busy_label.configure(text="Be patient, I have a lot of data to read")
self.RSM = Reciprocal(self.file_path)
self.RSM.readfile()
self.RSM.refine_data()
self.busy_label.configure(text="")
def create_rsm(self):
if self.RSM is not None:
self.busy_label.configure(text="Busy! Plotting %s data points." % len(self.RSM.intensity))
if self.rsm_parallel_lower_entry.get() != "":
self.rsm_parallel_lower = float(self.rsm_parallel_lower_entry.get())
if self.rsm_parallel_upper_entry.get() != "":
self.rsm_parallel_upper = float(self.rsm_parallel_upper_entry.get())
if self.rsm_normal_lower_entry.get() != "":
self.rsm_normal_lower = float(self.rsm_normal_lower_entry.get())
if self.rsm_normal_upper_entry.get() != "":
self.rsm_normal_upper = float(self.rsm_normal_upper_entry.get())
x = self.RSM.q_parallel
y = self.RSM.q_normal
if self.rsm_scale == "linear":
z = self.RSM.intensity
else:
z = self.RSM.log_intensity
ax = self.rsm_plot_figure.gca()
ax.clear()
ax.tricontourf(x, y, z, 1000, cmap="gist_rainbow")
ax.tricontour(x, y, z, 8, colors="black")
ax.set_ylabel(r"$q_{\perp} [\AA^{-1}]$")
ax.set_xlabel(r"$q_{\parallel} [\AA^{-1}]$")
示例7: App
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class App(object):
def __init__(self):
#настройка окружения
self.pathtoapp = path2program.abspath(".")
self.lst = [x for x in listdir(".") if ".prg" in x] #получаем список файлов с расширением prg
if len(self.lst)==0:
print("No prg file found in directory")
input()
_exit(0)
self.currentfileindex = 0 #устанавливаем индекс текущего файла
#настройка графики
self.window = Tk()
self.window.title("PRG Viewer by Novicov: "+self.pathtoapp)
w = 850
h = 500
self.window.minsize(width=w-100,height=h-100)
self.window.maxsize(width=w,height=h)
#иконка
_lst = sys_argv[0].split('\\')
self.window.iconbitmap('\\'.join(_lst[:-1])+'\\PRGViewer-logo.ico')
#ПАНЕЛИ
# self.leftframe = Frame(self.window, bg="blue", width=int(w*0.667),height=h)
self.leftframe = Frame(self.window, bg="grey", width=int(w*0.667),height=h)
# self.bottomleftframe = Frame(self.leftframe, bg="red", width=w//4, height=int(h*0.2))
self.bottomleftframe = Frame(self.leftframe, bg="grey", width=w//4, height=int(h*0.2))
# self.rightframe = Frame(self.window, bg="yellow",width=int(w*0.333),height=h)
self.rightframe = Frame(self.window, bg="dark grey",width=int(w*0.333),height=h)
#canvas
self.set_canvas( self.leftframe, bg="dark green", width=int(w*0.667),height=int(h*0.8))
# self.set_canvas( self.leftframe, bg="light green", width=100,height=100)
#кнопки
self.nextButton = Button(self.bottomleftframe,text="Next",width=10)
self.prevButton = Button(self.bottomleftframe,text="Prev",width=10)
#Список фильтров
self.Filter = PRGListBox(self.rightframe,width=w-500)
#Выбор файла платы
self.infoText = StringVar()
self.infoText.set("Current file: "+self.lst[self.currentfileindex])
self.info = Label(self.rightframe,text=self.infoText.get())
self.listFilesText = StringVar()
self.listFilesText.set("\n".join(["Files: "]+self.lst))
self.listfiles = Label(self.rightframe,text=self.listFilesText.get(),anchor="w",justify=LEFT)
self.helpText = Label(self.rightframe, text="Use Next/Prev (Pg Down/Up) buttons for change file\n"+
"Use Up,Down,Right,Left buttons for move field\n"+
"Select row in ListBox for change vision mode\n"+
"Use +/- (p/m) buttons for scaling of field",anchor="n",justify=LEFT)
def set_path_and_current(self, filename):
'''
эта функция обрабатывает полный путь до файла
'''
try:
_lst = filename.split('\\')
self.path = '\\'.join(_lst[:-2])
chdir('\\'.join(_lst[:-1]))
print(listdir("."))
self.lst = [x for x in listdir(".") if ".prg" in x]
self.currentfileindex = self.lst.index(_lst[-1])
self.infoText.set("Current file: "+self.lst[self.currentfileindex])
self.info.configure(text=self.infoText.get())
self.listFilesText.set("\n".join(self.lst))
self.listfiles.configure(text=self.listFilesText.get())
self.canvas.configure(self.lst[self.currentfileindex])
self.canvas.setdefault(reper=True)
#рисуем
self.canvas.paint()
#здесь мы создаем группу
gr = list()
for item in self.canvas.field:
print(item[2][2])
if not (item[2][2] in gr):#выделяем уникальные данные
gr.append(item[2][2])
self.Filter.lst.delete(2,END)
for item in gr:
self.Filter.lst.insert(END,item)
except IOError:
self.infoText.set("Error")
self.info.configure(text=self.infoText.get())
def set_canvas(self,master=None,height=500,width=500,bg="grey" ):
if master==None:
master=self.window
self.canvas = prgCanvas(master,height=height,width=width,bg=bg)
def nextprev(self,direction):
self.currentfileindex+=1 if abs(direction)==direction else -1
#.........这里部分代码省略.........
示例8: Example
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("EGUANA")
self.style = ttk.Style()
self.style.theme_use("alt")
self.photoName = "eguana.gif"
self.frame = Frame(self, relief=FLAT, borderwidth=10,bg='#FADC46')
self.frame.pack(fill=BOTH, expand=True)
self.pack(fill=BOTH, expand=True)
self.setupMenuBar()
self.setupTopBar()
def setupMenuBar(self):
self.menubar = EguanaMenu(self.parent,self)
self.parent.config(menu=self.menubar)
def setupTopBar(self):
self.openButton3D = Button(self.frame,text="Select Directory for 3D EMA",relief=RAISED,command=self.askDirectory)
self.openButton3D.grid(row=0,column=0, sticky=N+S+E+W,padx=2,pady =2)
self.openButton2D = Button(self.frame,text="Select Directory for 2D EMA",relief=RAISED,command=self.askDirectory);
self.openButton2D.grid(row=2,column=2, sticky=N+S+E+W,padx=2,pady =2)
self.p1Button = Button(self.frame,text="Placeholder",relief=RAISED)
self.p1Button.grid(row=0,column=1, sticky=N+S+E+W,padx=2,pady =2)
self.p2Button = Button(self.frame,text="Placeholder",relief=RAISED)
self.p2Button.grid(row=0,column=2, sticky=N+S+E+W,padx=2,pady =2)
self.p3Button = Button(self.frame,text="Placeholder",relief=RAISED)
self.p3Button.grid(row=1,column=0, sticky=N+S+E+W,padx=2,pady =2)
self.p4Button = Button(self.frame,text="Placeholder",relief=RAISED)
self.p4Button.grid(row=1,column=2, sticky=N+S+E+W,padx=2,pady =2)
self.p5Button = Button(self.frame,text="Placeholder",relief=RAISED)
self.p5Button.grid(row=2,column=0, sticky=N+S+E+W,padx=2,pady =2)
self.p6Button = Button(self.frame,text="Placeholder",relief=RAISED)
self.p6Button.grid(row=2,column=1, sticky=N+S+E+W,padx=2,pady =2)
self.openButton3D.bind('<Motion>',self.cursorPosition)
self.openButton2D.bind('<Motion>',self.cursorPosition)
self.photo = PhotoImage(file="eguana.gif")
self.photo = self.photo.subsample(2);
self.photo_label = Label(self.frame,image=self.photo,borderwidth=0,highlightthickness=0)
self.photo_label.configure(bg='#FADC46')
self.photo_label.grid(row=1,column=1, sticky=N+S+E+W,padx=2,pady =2)
self.photo_label.image = self.photo
self.frame.columnconfigure(0, weight=1)
self.frame.columnconfigure(1, weight=1)
self.frame.columnconfigure(2, weight=1)
self.frame.rowconfigure(0, weight=1)
self.frame.rowconfigure(1, weight=1)
self.frame.rowconfigure(2, weight=1)
def askDirectory(self):
dirStr = filedialog.askdirectory()
if len(dirStr):
self.openButton3D.destroy()
self.openButton2D.destroy()
self.p1Button.destroy()
self.p2Button.destroy()
self.p3Button.destroy()
self.p4Button.destroy()
self.p5Button.destroy()
self.p6Button.destroy()
self.menubar.entryconfigure('Filter', state = 'active')
self.photo_label.destroy()
dirStr = 'Input Path : '+dirStr
self.frame.grid_forget()
self.infoFrame = Frame(self.frame, relief=FLAT, bg='#FADC46')
self.infoFrame.grid(row=0,column=0,columnspan=3, sticky=N+S+E+W,padx=2,pady =2)
self.directoryLabel = Label(self.infoFrame, text="No project currently selected",relief=FLAT)
self.directoryLabel.grid(row=0,column=0,columnspan=2, sticky=N+S+E+W,padx=2,pady =2)
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
self.link_first = True
self.items = []
self.place(relx=0.0, rely=0.0, relheight=0.62, relwidth=0.72)
self.configure(relief=GROOVE)
self.configure(borderwidth="2")
label_top = Label(self)
label_top.place(relx=0.42, rely=0.03, height=21, width=105)
label_top.configure(text="Select a file to read")
self.file_select = Button(self, command=self.fopen)
self.file_select.place(relx=0.43, rely=0.14, height=34, width=97)
self.file_select.configure(text="Select file")
self.back = Button(self, command=lambda: controller.show_frame('Main'))
self.back.place(relx=0.8, rely=0.87, height=34, width=97)
self.back.configure(text="Go back")
self.delimeter = Entry(self)
self.delimeter.place(relx=0.02, rely=0.11, relheight=0.06, relwidth=0.21)
self.delimeter.insert(0, ' -<>- ')
label_delim = Label(self)
label_delim.place(relx=0.02, rely=0.03, height=21, width=57)
label_delim.configure(text="Delimeter")
self.switch_label = Label(self)
self.switch_label.place(relx=0.73, rely=0.31, height=21, width=38)
self.switch_label.configure(text="Link")
self.switch_label2 = Label(self)
self.switch_label2.place(relx=0.9, rely=0.31, height=21, width=38)
self.switch_label2.configure(text="Name")
self.change_order = Button(self, command=self.switch_order)
self.change_order.place(relx=0.82, rely=0.31, height=24, width=32)
self.change_order.configure(text="<->")
name_or_link = Label(self)
name_or_link.place(relx=0.75, rely=0.19, height=21, width=97)
name_or_link.configure(text="Name or link first")
self.items_text = Text(self)
self.items_text.place(relx=0.02, rely=0.5, relheight=0.46, relwidth=0.76)
self.items_text.configure(wrap=tk.WORD)
label_items = Label(self)
label_items.place(relx=0.35, rely=0.42, height=21, width=35)
label_items.configure(text="Items")
self.commit_btn = Button(self, command=self.commit)
self.commit_btn.place(relx=0.83, rely=0.64, height=34, width=67)
self.commit_btn.configure(text="Commit")
self.Label12 = Label(self)
self.Label12.place(relx=0.02, rely=0.19, height=21, width=88)
self.Label12.configure(text="Link formatting (optional)")
self.link_part1 = Entry(self, fg='grey')
self.link_part1.place(relx=0.02, rely=0.28, relheight=0.06, relwidth=0.37)
self.link_part1.insert(0, "Start of the link here")
self.link_part1.bind('<Button-1>', lambda event: greytext(self.link_part1))
self.link_part2 = Entry(self, fg='grey')
self.link_part2.place(relx=0.02, rely=0.36, relheight=0.06, relwidth=0.37)
self.link_part2.insert(0, "End of the link here")
self.link_part2.bind('<Button-1>', lambda event: greytext(self.link_part2))
示例10: Tabblet
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class Tabblet():
def __init__(self):
self.tkvar = tkinter.Tk()
with open("options.json") as j:
joptions = json.load(j)
self.tkvar.wm_title("Tabblet")
self.tkvar.iconbitmap('resources\\tabbleto.ico')
self.screenwidth = self.tkvar.winfo_screenwidth()
self.screenheight = self.tkvar.winfo_screenheight()
self.windowwidth = int(joptions['width'])
self.windowheight = int(joptions['height'])
self.windowx = (self.screenwidth-self.windowwidth) / 2
self.windowy = ((self.screenheight-self.windowheight) / 2) - 27
self.geometrystring = '%dx%d+%d+%d' % (self.windowwidth, self.windowheight, self.windowx, self.windowy)
self.tkvar.geometry(self.geometrystring)
self.image_resetwindow = PhotoImage(file="resources\\resetwindow.gif")
self.button_resetwindow = Button(self.tkvar, command= lambda: self.tkvar.geometry(self.geometrystring))
self.button_resetwindow.configure(relief="flat", image=self.image_resetwindow)
self.button_resetwindow.pack(expand=False,anchor="ne")
self.tkvar.bind('<Configure>', lambda event: self.button_resetwindow.place(x=self.tkvar.winfo_width()-20, y=0))
self.tkvar.bind('<B1-Motion>', self.dragmotion)
self.tkvar.bind('<ButtonPress-1>', lambda event: self.mousestate(True))
self.tkvar.bind('<ButtonRelease-1>', lambda event: self.mousestate(False))
self.velocityx = 0
self.velocityy = 0
self.mousepositionsx = [2]
self.mousepositionsy = [2]
self.ismousepressed = False
self.labelvelocityind = Label(self.tkvar, text='•')
velocitythread = threading.Thread(target=self.velocitymanager)
velocitythread.daemon = True
velocitythread.start()
self.tkvar.mainloop()
def dragmotion(self, event):
#print(event.x, event.y)
self.mousepositionsx.append(event.x)
self.mousepositionsy.append(event.y)
self.mousepositionsx = self.mousepositionsx[-20:]
self.mousepositionsy = self.mousepositionsy[-20:]
print(event.x, event.y)
def mousestate(self, state):
self.ismousepressed = state
def velocitymanager(self):
while True:
if not self.ismousepressed:
try:
self.velocityx = (sum(self.mousepositionsx)/len(self.mousepositionsx)) - self.mousepositionsx[-1]
self.velocityy = (sum(self.mousepositionsy)/len(self.mousepositionsy)) - self.mousepositionsy[-1]
except:
self.velocityx = 0
self.velocityy = 0
self.velocityx = int(self.velocityx * 0.9)
self.velocityy = int(self.velocityy * 0.9)
#print(self.velocityx, self.velocityy, self.ismousepressed)
if abs(self.velocityx) < 2:
self.velocityx = 0
if abs(self.velocityy) < 2:
self.velocityy = 0
time.sleep(0.0165)
#60 fps baby
self.labelvelocityind.configure(text="•")
self.labelvelocityind.place(x=512+self.velocityx, y=288+self.velocityy)
self.mousepositionsx = self.mousepositionsx[1:]
self.mousepositionsy = self.mousepositionsy[1:]
示例11: Main
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class Main(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
self.db_set = False
self.configure(relief=GROOVE)
self.configure(borderwidth="2")
# Manual link adding
self.manual_btn = Button(self)
self.manual_btn.place(relx=0.07, rely=0.81, height=45, width=130)
self.manual_btn.configure(activebackground="#d9d9d9")
self.manual_btn.configure(highlightbackground="#d9d9d9")
self.manual_btn.configure(pady="0")
self.manual_btn.configure(text="Add manually")
self.manual_btn.configure(width=130)
self.file_btn = Button(self)
self.file_btn.place(relx=0.67, rely=0.81, height=45, width=150)
self.file_btn.configure(activebackground="#d9d9d9")
self.file_btn.configure(highlightbackground="#d9d9d9")
self.file_btn.configure(pady="0")
self.file_btn.configure(text="Add from file")
self.label = Label(self)
self.label.place(relx=0.08, rely=0.0, height=61, width=484)
self.label.configure(text="Create new playlists and add content to them")
self.label.configure(width=485)
self.listbox = Listbox(self)
self.listbox.place(relx=0.38, rely=0.22, relheight=0.31, relwidth=0.17)
self.listbox.configure(background="white")
self.listbox.configure(disabledforeground="#a3a3a3")
self.listbox.configure(foreground="#000000")
self.listbox.configure(selectmode=SINGLE)
self.listbox.configure(width=105)
for name, value in config.configparser.items('Playlists'):
if os.path.isdir(value):
self.listbox.insert('end', name)
else:
config.remove_value('Playlists', name)
self.listbox.bind('<<ListboxSelect>>', self.onselect)
self.label_name = Label(self)
self.label_name.place(relx=0.7, rely=0.22, height=31, width=84)
self.label_name.configure(foreground="#000000")
self.label_name.configure(text="Name")
self.label_name.configure(width=85)
self.entry = Entry(self)
self.entry.place(relx=0.63, rely=0.31, relheight=0.08, relwidth=0.29)
self.entry.configure(background="white")
self.entry.configure(foreground="#000000")
self.entry.configure(insertbackground="black")
self.entry.configure(takefocus="0")
self.entry.configure(width=175)
self.change_name = Button(self)
self.change_name.place(relx=0.7, rely=0.42, height=34, width=97)
self.change_name.configure(activebackground="#d9d9d9")
self.change_name.configure(highlightbackground="#d9d9d9")
self.change_name.configure(highlightcolor="black")
self.change_name.configure(pady="0")
self.change_name.configure(text="Rename")
self.change_name.configure(width=100)
self.new_playlist = Button(self, command=self.new_database)
self.new_playlist.place(relx=0.08, rely=0.28, height=54, width=107)
self.new_playlist.configure(activebackground="#d9d9d9")
self.new_playlist.configure(highlightbackground="#d9d9d9")
self.new_playlist.configure(highlightcolor="black")
self.new_playlist.configure(pady="0")
self.new_playlist.configure(text="Create new playlist")
self.new_playlist.configure(width=105)
self.db_name = Entry(self)
self.db_name.place(relx=0.07, rely=0.44, relheight=0.08, relwidth=0.22)
self.db_name.configure(fg='grey')
self.db_name.configure(width=135)
self.db_name.insert(0, "Input database name here")
self.db_name.bind('<Button-1>', lambda event: greytext(self.db_name))
def onselect(self, event):
w = event.widget
index = int(w.curselection()[0])
value = w.get(index)
set_database(config.configparser.get('Playlists', value))
if not database.check_integrity():
messagebox.showwarning('Integrity check failed', 'You might be missing some entries in your list')
if not self.db_set:
self.manual_btn.configure(command=lambda: self.controller.show_frame('AddManually'))
self.file_btn.configure(command=lambda: self.controller.show_frame('ReadFromFile'))
self.db_set = True
def new_database(self):
name = self.db_name.get()
names = config.configparser.options('Playlists')
print(name, names)
if name.strip() == '' or self.db_name.cget('fg') == 'grey':
#.........这里部分代码省略.........
示例12: ReadFromFile
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class ReadFromFile(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
self.link_first = True
self.items = []
self.place(relx=0.0, rely=0.0, relheight=0.62, relwidth=0.72)
self.configure(relief=GROOVE)
self.configure(borderwidth="2")
label_top = Label(self)
label_top.place(relx=0.42, rely=0.03, height=21, width=105)
label_top.configure(text="Select a file to read")
self.file_select = Button(self, command=self.fopen)
self.file_select.place(relx=0.43, rely=0.14, height=34, width=97)
self.file_select.configure(text="Select file")
self.back = Button(self, command=lambda: controller.show_frame('Main'))
self.back.place(relx=0.8, rely=0.87, height=34, width=97)
self.back.configure(text="Go back")
self.delimeter = Entry(self)
self.delimeter.place(relx=0.02, rely=0.11, relheight=0.06, relwidth=0.21)
self.delimeter.insert(0, ' -<>- ')
label_delim = Label(self)
label_delim.place(relx=0.02, rely=0.03, height=21, width=57)
label_delim.configure(text="Delimeter")
self.switch_label = Label(self)
self.switch_label.place(relx=0.73, rely=0.31, height=21, width=38)
self.switch_label.configure(text="Link")
self.switch_label2 = Label(self)
self.switch_label2.place(relx=0.9, rely=0.31, height=21, width=38)
self.switch_label2.configure(text="Name")
self.change_order = Button(self, command=self.switch_order)
self.change_order.place(relx=0.82, rely=0.31, height=24, width=32)
self.change_order.configure(text="<->")
name_or_link = Label(self)
name_or_link.place(relx=0.75, rely=0.19, height=21, width=97)
name_or_link.configure(text="Name or link first")
self.items_text = Text(self)
self.items_text.place(relx=0.02, rely=0.5, relheight=0.46, relwidth=0.76)
self.items_text.configure(wrap=tk.WORD)
label_items = Label(self)
label_items.place(relx=0.35, rely=0.42, height=21, width=35)
label_items.configure(text="Items")
self.commit_btn = Button(self, command=self.commit)
self.commit_btn.place(relx=0.83, rely=0.64, height=34, width=67)
self.commit_btn.configure(text="Commit")
self.Label12 = Label(self)
self.Label12.place(relx=0.02, rely=0.19, height=21, width=88)
self.Label12.configure(text="Link formatting (optional)")
self.link_part1 = Entry(self, fg='grey')
self.link_part1.place(relx=0.02, rely=0.28, relheight=0.06, relwidth=0.37)
self.link_part1.insert(0, "Start of the link here")
self.link_part1.bind('<Button-1>', lambda event: greytext(self.link_part1))
self.link_part2 = Entry(self, fg='grey')
self.link_part2.place(relx=0.02, rely=0.36, relheight=0.06, relwidth=0.37)
self.link_part2.insert(0, "End of the link here")
self.link_part2.bind('<Button-1>', lambda event: greytext(self.link_part2))
def fopen(self):
filename = askopenfilename()
if filename == '':
return
self.items.clear()
self.items_text.delete(1.0, 'end')
with open(filename, encoding='utf-8-sig') as f:
lines = f.read().splitlines()
delim = self.delimeter.get()
for line in lines:
try:
link, name = line.split(delim, 1)
if not self.link_first:
name, link = link, name
if '{DELETED} ' in name[:13]:
continue
s, e = self.get_link_formatting()
link = s + link + e
self.items += [(link, name)]
self.items_text.insert('end', ("name: " + name + "\nlink: " +
link + '\n\n'))
except ValueError:
print("Something went wrong: ", line)
def get_link_formatting(self):
#.........这里部分代码省略.........
示例13: EguanaGUI
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class EguanaGUI(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
# if not EguanaInit.eguana_root_dir_exists():
# EguanaInit.create_eguana_root_dir()
def initUI(self):
self.parent.title("EGUANA")
self.style = ttk.Style()
self.style.theme_use("alt")
self.photoName = "eguana.gif"
self.frame = Frame(self, relief=FLAT, borderwidth=10,bg='#FADC46')
self.frame.pack(fill=BOTH, expand=True)
self.pack(fill=BOTH, expand=True)
self.setupMenuBar()
self.setupTopBar()
def setupMenuBar(self):
self.menubar = EguanaMenu(self.parent,self)
self.parent.config(menu=self.menubar)
def setupTopBar(self):
self.supportedDevices = []
for fileName in [name for name in os.listdir('./machineConfig') if os.path.isfile('./machineConfig/' + name) and not name == 'eguanaMachineConfig.py' and name.endswith('.py')]:
# try:{
components = fileName.split('.')
fileName = components[0]
className = fileName[0].upper() + fileName[1:]
try:
module = __import__("machineConfig."+fileName,fromlist=["machineConfig."])
classVar = getattr(module,className)
except:
continue
self.supportedDevices.append(classVar())
# except:
# pass
self.selectMachineFrame = Frame(self.frame,relief=FLAT,bg='#FADC46')
self.selectMachineFrame.pack(fill=BOTH,expand=True)
self.setupSelectMachineButtons()
def setupSelectMachineButtons(self):
numDevices = len(self.supportedDevices)
numColumns = 3
numRows = math.ceil((numDevices+1)/3)
self.photo = PhotoImage(file="eguana.gif")
self.photo = self.photo.subsample(2);
self.photo_label = Label(self.selectMachineFrame,image=self.photo,borderwidth=0,highlightthickness=0)
self.photo_label.configure(bg='#FADC46')
self.photo_label.grid(row=int(numRows/2),column=1, sticky=N+S+E+W,padx=2,pady =2)
self.photo_label.image = self.photo
index = 0
for i in range(numRows):
for j in range(numColumns):
if not(j == 1 and i == int(numRows/2)) and (index < numDevices):
device = self.supportedDevices[index]
b = Button(self.selectMachineFrame,text=device.name,relief=RAISED, command=lambda device=device :self.machineButtonPressed(device))
b.grid(row=i,column=j, sticky=N+S+E+W,padx=2,pady =2)
index += 1
for i in range(numRows):
self.selectMachineFrame.rowconfigure(i,weight=1)
for i in range(numColumns):
self.selectMachineFrame.columnconfigure(i,weight=1)
def machineButtonPressed(self,inputDevice):
dirStr = filedialog.askdirectory()
if len(dirStr) and inputDevice.isDirectoryValid(dirStr):
inputDevice.setDirPath(dirStr)
EguanaModel().machine = inputDevice
self.selectMachineFrame.destroy()
self.menubar.inputSelected()
self.photo_label.destroy()
dirStr = 'Input Path : '+dirStr
#.........这里部分代码省略.........
示例14: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
#.........这里部分代码省略.........
self.working_output_label.place(height=25, width=200, x=10, y=100)
self.log_frame.place(height=135, width=400, x=240, y=270)
self.log_text.place(height=115, width=380, x=10, y=10)
self.plot_frame.place(x=640, y=10, width=360, height=395)
self.switch_plot_left_button.place(x=5, y=5, height=30, width=30)
self.switch_plot_right_button.place(x=325, y=5, height=30, width=30)
self.plot_label.place(x=35, y=5, height=25, width=295)
self.pyrometer_plot_frame.place(x=5, y=40, width=350, height=350)
self.oven_temperature_plot_frame.place(x=5, y=40, width=350, height=350)
self.power_ouput_plot_frame.place(x=5, y=40, width=350, height=350)
self.pyrometer_plot.place(x=0, y=0, width=350, height=350)
self.oven_temperature_plot.place(x=0, y=00, width=350, height=350)
self.power_ouput_plot.place(x=0, y=0, width=350, height=350)
self.oven_temperature_plot_frame.lift()
def start_label_updater(self):
"""Read values from instrument objects every second, display them, plot them and write in a logfile"""
self.start_time = datetime.now()
def update_labels():
while True:
pyrometer_temperature = "---"
oven_temperature = "---"
working_output = "---"
working_setpoint = "---"
runtime = (datetime.now() - self.start_time).seconds / 60.0
if self.PLD is not None:
oven_temperature = self.PLD.oven_temp.get()
self.oven_temperature_plot.add_datapoint(runtime, oven_temperature)
self.oven_temperature_label.configure(text="Oven temperature: %s °C" % oven_temperature)
working_output = self.PLD.working_output.get()
self.power_ouput_plot.add_datapoint(runtime, working_output)
self.working_output_label.configure(text="Working output: %s %%" % working_output)
working_setpoint = self.PLD.working_setpoint.get()
self.working_setpoint_label.configure(text="Working setpoint: %s °C" % working_setpoint)
if self.pyrometer is not None:
pyrometer_temperature = self.pyrometer.temperature.get()
self.pyrometer_plot.add_datapoint(runtime, pyrometer_temperature)
self.external_temperature_label.configure(text="Sample temperature %s °C" % pyrometer_temperature)
logstring = "Time: " + strftime("%X") \
+ ("Oven temperature: %s °C" % oven_temperature).ljust(28, " ") \
+ ("Power Output %s %%" % working_output).ljust(28, " ")\
+ ("Working Setpoint: %s °C" % working_setpoint).ljust(28, " ")\
+ ("Pyrometer temperature: %s °C" % pyrometer_temperature).ljust(28, " ") \
+ "\n"
printstring = "Time: " + strftime("%X") \
+ ("Oven temperature: %s °C" % oven_temperature).ljust(28, " ") \
+ ("Pyrometer temperature: %s °C" % pyrometer_temperature).ljust(28, " ")\
+ "\n"
self.log_text.insert(END, printstring)
sleep(0.5)
self.label_updater._target = update_labels
self.label_updater.start()
if self.PLD is not None and self.pyrometer is not None:
self.start_pyrometer_pld_communication()
示例15: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import configure [as 别名]
class dodgygame:
def __init__(self):
tkvar = Tk()
tkvar.resizable(0,0)
tkvar.wm_title('Dodgy')
tkvar.iconbitmap('Excl.ico')
arenasize = 40
self.xpos = int((arenasize-1)/2)
self.ypos = int((arenasize-1)/2)
self.data = ['#'*arenasize, '#'*arenasize]
for x in range(arenasize-2):
self.data[1:1] = ['#' + '.'*(arenasize-2) + '#']
self.labelframe = Frame(tkvar)
self.labelframe.grid(row=1, column=0, columnspan=100)
#Allows me to center the gui units
self.datalabel = Label(tkvar, text='\n'.join(self.data), font=('Terminal', 10))
self.datalabel.grid(row=0, column=0, columnspan=100)
self.stepslabel = Label(self.labelframe, text='0', font=('Consolas', 10))
self.stepslabel.grid(row=0, column=0)
self.collectlabel = Label(self.labelframe, text='0', font=('Consolas', 10), bg="#ccc")
self.collectlabel.grid(row=0, column=1)
self.bomblabel = Label(self.labelframe, text='0', font=('Consolas', 10))
self.bomblabel.grid(row=0, column=2)
self.phantlabel = Label(self.labelframe, text='0',font=('Consolas', 10), bg="#ccc")
self.phantlabel.grid(row=0, column=3)
self.poslabel = Label(self.labelframe, text=str(self.xpos) + " " + str(self.ypos), font=('Consolas', 10))
self.poslabel.grid(row=0, column=4)
self.helplabel = Label(tkvar, text="Press H for help ->", font=('Consolas', 8))
self.helplabel.grid(row=2, column=0, columnspan=100)
self.consolelabel = Label(tkvar, text="Welcome", font=("Terminal", 8), width=arenasize, height=4)
self.consolelabeldata = []
self.consolelabel.configure(anchor="nw", justify="left")
self.consolelabel.grid(row=3, column=0)
tkvar.bind('w', lambda data=self.data: mfresh(ymove=-1))
tkvar.bind('<Up>', lambda data=self.data: mfresh(ymove=-1))
tkvar.bind('s', lambda data=self.data: mfresh(ymove=1))
tkvar.bind('<Down>', lambda data=self.data: mfresh(ymove=1))
tkvar.bind('a', lambda data=self.data: mfresh(xmove=-1))
tkvar.bind('<Left>', lambda data=self.data: mfresh(xmove=-1))
tkvar.bind('d', lambda data=self.data: mfresh(xmove=1))
tkvar.bind('<Right>', lambda data=self.data: mfresh(xmove=1))
#tkvar.bind('c', lambda data=self.data: spawncandy())
tkvar.bind('j', lambda data=self.data: spawnbomb())
tkvar.bind('z', lambda data=self.data: spawnbomb())
tkvar.bind('k', lambda data=self.data: spawnphantom())
tkvar.bind('x', lambda data=self.data: spawnphantom())
tkvar.bind('r', lambda data=self.data: restart())
tkvar.bind('h', lambda data=self.data: helpreel())
tkvar.bind('<Control-w>', quit)
self.candylist = []
self.enemylist = []
self.bomblist = []
self.phantomlist = []
self.goldcandylist = []
self.entlist = []
self.symbols = {'char':'H', 'wall':'#', 'floor':' '}
self.stepstaken = 0
self.isdeath = False
self.candyspawnrate = 4
self.collections = 0
self.enemyspawnrate = 50
self.enemyspawnmindist = 9
self.enemydocollide = False
self.bombs = 0
self.bombcost = 4
self.phantomcost = 60
self.goldcandyflashrate = 8
self.goldcandyspawnrate = 40
self.goldcandyspawnrand = 4
self.helplabelindex = -1
self.helplabeltexts = [
"<WASD>=Movement <J>=Bomb <K>=Phantom <R>=Restart ->",
"<UDLR>=Movement <Z>=Bomb <X>=Phantom <R>=Restart ->",
"<LMB>=Movement <RMB>=Bomb <MMB>=Phantom/Restart ->",
self.symbols['char'] + " = You ->",
enemy.symbol + " = Exclamator ->",
candy.symbol + " = Candy ->",
bomb.symbol + " = Bomb ->",
"Avoid the Exclamators ->",
"Collect candy to earn bombs ->",
"Drop bombs to snare Exclamators ->",
"Deploy phantoms to distract Exclamators ->",
#.........这里部分代码省略.........