def __init__(self, parent=None):
tk.Tk.__init__(self, parent)
self.parent = parent
self.log_text = tkst.ScrolledText(self, state=tk.DISABLED)
self.log_text.configure(font='TkFixedFont')
self.log_text.pack(side=tk.LEFT, padx=5, pady=5)
self.start_button = ttk.Button(parent, text='Start ConsoleMini', state=tk.NORMAL,
command=self.start_twitch_bits_info)
self.start_button.pack(side=tk.TOP, padx=12, pady=12)
self.stop_button = ttk.Button(parent, text='Stop ConsoleMini', state=tk.DISABLED,
command=self.stop_twitch_bits_info)
self.stop_button.pack(side=tk.TOP, padx=12, pady=12)
self.update_button = ttk.Button(parent, text='Manual update JSON', state=tk.DISABLED,
command=self.manual_update_json)
self.update_button.pack(side=tk.TOP, padx=12, pady=12)
python类Button()的实例源码
def chosen(self, label, items, choice, name):
#for child in self.mainframe.winfo_children():
# child.destroy()
self.add_emoji()
self.add_trace()
self.set_title(label)
ind = 0
for item in items:
col = ind%4 + 1
row = ind/4 + 1
if name=="true":
if item==choice:
ttk.Button(self.mainframe, text=item).grid(column=col, row=row, sticky=N+S+E+W)
else:
ttk.Button(self.mainframe, text="").grid(column=col, row=row, sticky=N+S+E+W)
else:
if item==choice:
ttk.Button(self.mainframe, text=item, image=images[item], compound="top").grid(column=col, row=row, sticky=N+S+E+W)
else:
ttk.Button(self.mainframe, text="", image=gray, compound="top").grid(column=col, row=row, sticky=N+S+E+W)
ind+=1
def robot(self, label,items, name):
for child in self.mainframe.winfo_children():
child.destroy()
self.add_emoji()
self.add_trace()
self.set_title(label)
ind = 0
for item in items:
col = ind%4 + 1
row = ind/4 + 1
if name=="true":
ttk.Button(self.mainframe, text=item).grid(column=col, row=row, sticky=N+S+E+W)
else:
ttk.Button(self.mainframe, text=item, image=images[item], compound="top").grid(column=col, row=row, sticky=N+S+E+W)
ind+=1
def chosen(self, label, items, choice, name):
#for child in self.mainframe.winfo_children():
# child.destroy()
self.add_emoji()
self.add_trace()
self.set_title(label)
ind = 0
for item in items:
col = ind%4 + 1
row = ind/4 + 1
if name=="true":
if item==choice:
ttk.Button(self.mainframe, text=item).grid(column=col, row=row, sticky=N+S+E+W)
else:
ttk.Button(self.mainframe, text="").grid(column=col, row=row, sticky=N+S+E+W)
else:
if item==choice:
ttk.Button(self.mainframe, text=item, image=images[item], compound="top").grid(column=col, row=row, sticky=N+S+E+W)
else:
ttk.Button(self.mainframe, text="", image=gray, compound="top").grid(column=col, row=row, sticky=N+S+E+W)
ind+=1
def robot(self, label,items, name):
for child in self.mainframe.winfo_children():
child.destroy()
self.add_emoji()
self.add_trace()
self.set_title(label)
ind = 0
for item in items:
col = ind%4 + 1
row = ind/4 + 1
if name=="true":
ttk.Button(self.mainframe, text=item).grid(column=col, row=row, sticky=N+S+E+W)
else:
ttk.Button(self.mainframe, text=item, image=images[item], compound="top").grid(column=col, row=row, sticky=N+S+E+W)
ind+=1
def chosen(self, label, items, choice, name):
#for child in self.mainframe.winfo_children():
# child.destroy()
self.add_emoji()
self.add_trace()
self.set_title(label)
ind = 0
for item in items:
col = ind%4 + 1
row = ind/4 + 1
if name=="true":
if item==choice:
ttk.Button(self.mainframe, text=item).grid(column=col, row=row, sticky=N+S+E+W)
else:
ttk.Button(self.mainframe, text="").grid(column=col, row=row, sticky=N+S+E+W)
else:
if item==choice:
ttk.Button(self.mainframe, text=item, image=images[item], compound="top").grid(column=col, row=row, sticky=N+S+E+W)
else:
ttk.Button(self.mainframe, text="", image=gray, compound="top").grid(column=col, row=row, sticky=N+S+E+W)
ind+=1
def _setup_widgets(self):
themes_lbl = ttk.Label(self, text="Themes")
themes = self.style.theme_names()
self.themes_combo = ttk.Combobox(self, values=themes, state="readonly")
self.themes_combo.set(themes[0])
self.themes_combo.bind("<<ComboboxSelected>>", self._theme_sel_changed)
change_btn = ttk.Button(self, text='Change Theme',
command=self._change_theme)
theme_change_checkbtn = ttk.Checkbutton(self,
text="Change themes when combobox item is activated",
variable=self.theme_autochange)
themes_lbl.grid(ipadx=6, sticky="w")
self.themes_combo.grid(row=0, column=1, padx=6, sticky="ew")
change_btn.grid(row=0, column=2, padx=6, sticky="e")
theme_change_checkbtn.grid(row=1, columnspan=3, sticky="w", pady=6)
top = self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
self.grid(row=0, column=0, sticky="nsew", columnspan=3, rowspan=2)
def _new_state(self, widget, newtext):
widget = self.nametowidget(widget)
if not newtext:
goodstates = ["disabled"]
font_extra = 0
else:
# set widget state according to what has been entered in the entry
newstates = set(newtext.split()) # eliminate duplicates
# keep only the valid states
goodstates = [state for state in newstates if state in states]
# define a new font size based on amount of states
font_extra = 2 * len(goodstates)
# set new widget state
for widget in self.update_widgets:
reset_state(widget) # remove any previous state from the widget
widget.state(goodstates)
# update Ttk Button font size
self._set_font(font_extra)
return 1
def search(self, event=None):
global run
run = True
input = self.url_input.get(0.0, END).replace('\n', '').replace(' ', '').replace('\t', '')
self.reset()
self.q = Queue.Queue()
t = Thread(target=self.get_results, args=[input])
t.daemon = True
t.start()
self.disable_search()
self.search_progress = ttk.Progressbar(self.mainframe, length=200, mode='indeterminate')
self.search_progress.pack()
self.search_progress.start(20)
self.cancel = ttk.Button(self.mainframe, text='Cancel', command=self.cancel_search)
self.cancel.pack()
self.master.after(100, self.add_results)
def create_custom_frame(self):
self.custom_frame = ttk.Frame(self.mainframe)
self.custom_title = ttk.Label(self.custom_frame, text='Custom tags:')
self.artist_label = ttk.Label(self.custom_frame, text='Artist: ')
self.artist_input = Text(self.custom_frame, width=20, height=1, font=self.font)
self.title_label = ttk.Label(self.custom_frame, text='Title: ')
self.title_input = Text(self.custom_frame, width=20, height=1, font=self.font)
self.album_label = ttk.Label(self.custom_frame, text='Album: ')
self.album_input = Text(self.custom_frame, width=20, height=1, font=self.font)
self.cover_art = ttk.Button(self.custom_frame, text='Browse for cover art', command=self.cover_art_browse)
self.cover_art_path = Entry(self.custom_frame, width=20, font=self.font)
self.custom_submit = ttk.Button(self.custom_frame, text='Download using custom tags', command=self.custom)
self.custom_title.grid(row=0, columnspan=2)
self.artist_label.grid(column=0, row=1)
self.artist_input.grid(column=1, row=1)
self.title_label.grid(column=0, row=2)
self.title_input.grid(column=1, row=2)
self.album_label.grid(column=0, row=3)
self.album_input.grid(column=1, row=3)
self.cover_art.grid(column=0, row=4)
self.cover_art_path.grid(column=1, row=4)
self.custom_submit.grid(row=5, columnspan=2, sticky=EW, pady=10)
self.custom_frame.pack(pady=10)
def add_file(self):
try:
result = self.download_queue.get(0)
if result == 0:
self.error = ttk.Label(self.mainframe, text='Error: ffmpeg is not installed.', font=self.font, foreground='#ff0000')
self.error.pack()
else:
self.file = result.replace('/', '\\')
text = 'Open %s' % self.file
self.file_button = ttk.Button(self.mainframe, text=text, command=partial(self.open_file, self.file))
self.file_button.pack()
self.enable_search()
self.download_progress.pack_forget()
self.download_progress.destroy()
self.results_label.pack_forget()
self.results_label.destroy()
self.results_frame.pack_forget()
self.results_frame.destroy()
except Queue.Empty:
self.master.after(100, self.add_file)
def raise_message(log):
if "Label(s) %s are not present" in log.msg:
box = tk.Toplevel(root)
box.title('Error')
message = ttk.Label(box, text = log.msg % log.args)
labels = {}
for f in app.filenames:
labels[os.path.basename(f)] = " ".join(sorted(multiCIF._alllabels(f)))
advice = ttk.Label(box, text = "Valid labels are:\n{0}".format( "".join( ["{0:40s}: {1:30s}\n".format(p, labels[p]) for p in labels] )))
tip = ttk.Label(box, text="[ Tip: Regular expressions can also be used to centre labels ]")
button = ttk.Button(box, text='OK', command= lambda: box.destroy())
message.grid(row = 0, padx = 5, pady = 5)
advice.grid(row = 1, padx = 5, pady = 5)
tip.grid(row=2, padx=5, pady=5)
button.grid(row = 3, padx = 5, pady = 5)
root.wait_window(window=box)
else:
pass
#tkMessageBox.showerror('Error',log.msg)
def __init__(self, parent, buttontext, mycommand,r,c):
ttk.Button.__init__(self, parent)
self.config(text = buttontext, command=mycommand)
self.grid(row=r,column=c)
def footer(self):
# Run button
run_button = ttk.Button(self.master, text = "Run", command = self.run)
# Exit button
exit_button = ttk.Button(self.master, text = "Exit", command = self.close_window)
# Layout
run_button.place(relwidth = 0.1, relx = 0.9, rely = 1, x = -5, y = -5, anchor = "se")
exit_button.place(relwidth = 0.1, relx = 1, rely = 1, x = -5, y = -5, anchor = "se")
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice, image=images[self.choice], compound="top",command=lambda:human_choice(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice,command=lambda:human_choice(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice, image=images[self.choice], compound="top",command=lambda:human_prediction(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice,command=lambda:human_prediction(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
################################################
def add_emoji(self):
ttk.Button(self.mainframe, text="good", image=good, compound="top", command=lambda:juge("good")).grid(column=1, row=4, sticky=N+S+E+W)
ttk.Button(self.mainframe, text="lol", image=lol, compound="top", command=lambda:juge("lol")).grid(column=2, row=4, sticky=N+S+E+W)
ttk.Button(self.mainframe, text="wtf", image=wtf, compound="top", command=lambda:juge("wtf")).grid(column=3, row=4, sticky=N+S+E+W)
ttk.Button(self.mainframe, text="bad", image=bad, compound="top", command=lambda:juge("bad")).grid(column=4, row=4, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice, image=images[self.choice], compound="top",command=lambda:human_choice(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice,command=lambda:human_choice(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice, image=images[self.choice], compound="top",command=lambda:human_prediction(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice,command=lambda:human_prediction(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
################################################
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice, image=images[self.choice], compound="top",command=lambda:human_choice(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice,command=lambda:human_choice(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def __init__(self,choice,frame,row,col):
self.choice = choice
self.button = ttk.Button(frame, text=self.choice, image=images[self.choice], compound="top",command=lambda:human_prediction(self.choice)).grid(column=col, row=row, sticky=N+S+E+W)
def add_emoji(self):
ttk.Button(self.mainframe, text="good", image=good, compound="top", command=lambda:juge("good")).grid(column=1, row=4, sticky=N+S+E+W)
ttk.Button(self.mainframe, text="lol", image=lol, compound="top", command=lambda:juge("lol")).grid(column=2, row=4, sticky=N+S+E+W)
ttk.Button(self.mainframe, text="absurd", image=wtf, compound="top", command=lambda:juge("wtf")).grid(column=3, row=4, sticky=N+S+E+W)
ttk.Button(self.mainframe, text="bad", image=bad, compound="top", command=lambda:juge("bad")).grid(column=4, row=4, sticky=N+S+E+W)
def setUp(self):
super(WidgetTest, self).setUp()
self.widget = ttk.Button(self.root, width=0, text="Text")
self.widget.pack()
self.widget.wait_visibility()
def create(self, **kwargs):
return ttk.Button(self.root, **kwargs)
def test_invoke(self):
success = []
btn = ttk.Button(self.root, command=lambda: success.append(1))
btn.invoke()
self.assertTrue(success)