def __setup_styles(self):
# custom ttk styles
style = ttk.Style(self.master)
arrow_layout = lambda dir: (
[('Button.focus', {'children': [('Button.%sarrow' % dir, None)]})]
)
style.layout('L.TButton', arrow_layout('left'))
style.layout('R.TButton', arrow_layout('right'))
python类Button()的实例源码
def __place_widgets(self):
# header frame and its widgets
hframe = ttk.Frame(self)
lbtn = ttk.Button(hframe, style='L.TButton', command=self._prev_month)
rbtn = ttk.Button(hframe, style='R.TButton', command=self._next_month)
self._header = ttk.Label(hframe, width=15, anchor='center')
# the calendar
self._calendar = ttk.Treeview(show='', selectmode='none', height=7)
# pack the widgets
hframe.pack(in_=self, side='top', pady=4, anchor='center')
lbtn.grid(in_=hframe)
self._header.grid(in_=hframe, column=1, row=0, padx=12)
rbtn.grid(in_=hframe, column=2, row=0)
self._calendar.pack(in_=self, expand=1, fill='both', side='bottom')
def _setup_widgets(self):
btn = ttk.Button(self, text='Enter states and watch')
entry = ttk.Entry(self, cursor='xterm', validate="key")
entry['validatecommand'] = (self.register(self._new_state), '%W', '%P')
entry.focus()
self.update_widgets.append(btn)
entry.validate()
entry.pack(fill='x', padx=6)
btn.pack(side='left', pady=6, padx=6, anchor='n')
self.pack(fill='both', expand=1)
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)
def show_window(self):
self.mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
self.mainframe.columnconfigure(0, weight=1)
self.mainframe.rowconfigure(0, weight=1)
ttk.Label(self.mainframe, text=" ").grid(column=0, row=0, sticky=(N,W))
ttk.Label(self.mainframe, text='1. Pair your Aurora').grid(column=1, row=1, sticky=(N, W))
ttk.Label(self.mainframe, text='IP Address').grid(column=1, row=2, sticky=(N, W))
ttk.Entry(self.mainframe, width=35, textvariable=self.ip_addr).grid(column=2, row=2, columnspan=2, sticky=(N, W))
ttk.Button(self.mainframe, width=12, text='Pair', command=self.authenticate_with_aurora).grid(column=4, row=2, sticky=(N,W))
ttk.Label(self.mainframe, text='2. Make a color palette').grid(column=1, row=3, sticky=(N, W))
ttk.Button(self.mainframe, text="Add Color", command=self.add_color_to_palette).grid(column=1, row=4, sticky=(N, W))
ttk.Label(self.mainframe, textvariable=self.curr_palette_string, wraplength=500).grid(column=2, row=4, columnspan=2, sticky=(N, W))
ttk.Button(self.mainframe, width=12, text="Clear palette", command=self.clear_palette).grid(column=4, row=4, sticky=(N, W))
if (not self.is_windows):
ttk.Label(self.mainframe, text='3. Build your plugin').grid(column=1, row=5, sticky=(N, W))
else:
ttk.Button(self.mainframe, width=18, text="Generate Palette", command=self.write_palette_for_sdk).grid(column=1, row=5, sticky=(N, W))
ttk.Label(self.mainframe, text='Plugin Location').grid(column=1, row=6, sticky=(N, W))
ttk.Entry(self.mainframe, width=35, textvariable=self.plugin_dir_path).grid(column=2, row=6, columnspan=2, sticky=(N, W))
ttk.Button(self.mainframe, width=12, text='Browse', command=self.get_plugin_dir).grid(column=4, row=6, sticky=(N, W))
if (not self.is_windows):
ttk.Button(self.mainframe, text='Build', command=self.build_plugin).grid(column=2, row=7, columnspan=1, sticky=(N,E))
ttk.Button(self.mainframe, text='Upload & Run', command=self.play_plugin).grid(column=3, row=7, columnspan=1, sticky=N)
ttk.Button(self.mainframe, width=12, text='Stop Plugin', command=self.stop_plugin).grid(column=4, row=7, columnspan=1, sticky=(N, W))
ttk.Label(self.mainframe, text=" ").grid(column=5, row=8, sticky=(N,W))
ttk.Label(self.mainframe, text=" ").grid(column=5, row=9, sticky=(N,W))
self.root.mainloop()
def show_popup(self):
popup = Tk()
popup.wm_title("Msg from %s" % host)
popup.geometry("480x320+300+300")
label = Label(popup, text=msg)
label.pack(side="top", fill="x", pady=10)
B1 = Button(popup, text="Okay", command = popup.destroy)
B1.pack()
popup.mainloop()
def _addModules(self, frame, matrix_labels, ui, layer, horizontal, item, modules):
for module in modules:
if isinstance(module, ModuleCollection):
if module.is_loop:
item = self._addModules(frame,
matrix_labels,
ui,
layer,
horizontal,
item,
module.module_list)
continue
sub_state = HeaderState(module.module_list,
frame,
matrix_labels,
ui,
layer + 1,
horizontal)
self.sub_header_states.append(sub_state)
if horizontal:
button = ttk.Button(frame,
text=str(module),
command=lambda col=item: self._toggleCol(col))
else:
button = ttk.Button(frame,
text=str(module),
command=lambda row=item: self._toggleRow(row))
self.buttons.append(button)
item = item + 1
return item
def write_music():
fo.write('''"'''+current_file+'''"'''+', music\n')
time.sleep(0.1)
mixer.stop()
mixer.init()
play_sound()
#btn = ttk.Button(c, text="load image", command=showImage)
#lbl1 = ttk.Label(c)
#btn.grid(column=0, row=0, sticky=N, pady=5, padx=5)
#lbl1.grid(column=1, row=1, sticky=N, pady=5, padx=5)
def __init__(self):
self.passwd = None
self.do_update = False
# current working directory
self.cwd = os.getcwd()
self.bemoss_dir = self.cwd.replace('bemoss_gui', 'bemoss_os/')
img_path = self.find_img()
self.logo = ImageTk.PhotoImage(Image.open(img_path).resize((350,125)))
self.img = ttk.Label(root, image=self.logo, justify='center')
self.img.pack(fill=Tkinter.Y, expand=True, padx=5, pady=30)
# logoimage
self.ip_addr = self.getIPs()
self.ipframe = Tkinter.LabelFrame(root, text='Your IP address:')
self.ip_label = Tkinter.Label(self.ipframe, text=self.ip_addr, font=('Courier', 12, 'bold'))
self.ip_label.pack()
self.ipframe.pack(fill=Tkinter.X, expand=True, padx=15)
# IP
self.button_quit = ttk.Button(root, text='Run BEMOSS', command=self.run_software)
self.button_quit.pack(side=Tkinter.LEFT, fill=Tkinter.BOTH, expand=True, pady=15, padx=10)
self.button_runNode = ttk.Button(root, text='Run BEMOSS Node', command=self.run_software_asnode)
self.button_runNode.pack(side=Tkinter.LEFT, fill=Tkinter.BOTH, expand=True, pady=15, padx=10)
self.button_run = ttk.Button(root, text='Stop BEMOSS', command=self.stop_software)
self.button_run.pack(side=Tkinter.LEFT, fill=Tkinter.BOTH, expand=True, pady=15, padx=10)
self.button_adv = ttk.Button(root, text='Advanced Setting', command=self.adv_set)
self.button_adv.pack(side=Tkinter.LEFT, fill=Tkinter.BOTH, expand=True, pady=15, padx=10)
# buttons
def get_passwd(self):
self.passwd_window = Tkinter.Toplevel(self.frame2)
self.passwd_window.title('Log In')
x = self.frame2.winfo_rootx()
y = self.frame2.winfo_rooty()
self.passwd_window.geometry('350x130+%d+%d' % (x+150, y+100))
self.passwd_window.lift()
self.passwd_window.columnconfigure(0, weight=1)
self.passwd_window.columnconfigure(1, weight=1)
self.passwd_window.columnconfigure(2, weight=1)
self.passwd_window.columnconfigure(3, weight=2)
self.passwd_window.columnconfigure(4, weight=2)
self.passwd_window.columnconfigure(5, weight=1)
self.passwd_window.rowconfigure(0, weight=1)
self.passwd_window.rowconfigure(1, weight=2)
self.passwd_window.rowconfigure(2, weight=2)
self.passwd_window.rowconfigure(3, weight=2)
self.passwd_window.rowconfigure(4, weight=1)
self.passwd_window.resizable(False, False)
reminder = ttk.Label(self.passwd_window, text='Please input the system password.')
reminder.grid(row=1, column=1, columnspan=4, sticky='w')
self.pswd = Tkinter.StringVar()
pwentry = Tkinter.Entry(self.passwd_window, textvariable=self.pswd, width=30)
pwentry.focus_set()
pwentry.grid(row=2, column=3, columnspan=2, sticky='w', padx=10)
pwentry.config(show='*')
pswdlabel = ttk.Label(self.passwd_window, text='Password:')
pswdlabel.grid(row=2, column=2, sticky='e', padx=10)
confirm_but = ttk.Button(self.passwd_window, text='Confirm', command=self.pwconfirm)
confirm_but.grid(row=3, column=4, sticky='w', padx=5)
clear_but = ttk.Button(self.passwd_window, text='Clear',
command=lambda: pwentry.delete(0, Tkinter.END))
clear_but.grid(row=3, column=3, sticky='e', padx=5)
self.passwd_window.bind('<Return>', self.shortcut)
def get_passwd_ocf(self):
self.passwd_window_ocf = Tkinter.Toplevel(self.frame3)
self.passwd_window_ocf.title('Postgres Auth(System Password)')
x = self.frame3.winfo_rootx()
y = self.frame3.winfo_rooty()
self.passwd_window_ocf.geometry('350x130+%d+%d' % (x+150, y+100))
self.passwd_window_ocf.lift()
self.passwd_window_ocf.columnconfigure(0, weight=1)
self.passwd_window_ocf.columnconfigure(1, weight=1)
self.passwd_window_ocf.columnconfigure(2, weight=1)
self.passwd_window_ocf.columnconfigure(3, weight=2)
self.passwd_window_ocf.columnconfigure(4, weight=2)
self.passwd_window_ocf.columnconfigure(5, weight=1)
self.passwd_window_ocf.rowconfigure(0, weight=1)
self.passwd_window_ocf.rowconfigure(1, weight=2)
self.passwd_window_ocf.rowconfigure(2, weight=2)
self.passwd_window_ocf.rowconfigure(3, weight=2)
self.passwd_window_ocf.rowconfigure(4, weight=1)
self.passwd_window_ocf.resizable(False, False)
reminder = ttk.Label(self.passwd_window_ocf, text='Please input the system password.')
reminder.grid(row=1, column=1, columnspan=4, sticky='w')
self.pswd_ocf = Tkinter.StringVar()
pwentry = Tkinter.Entry(self.passwd_window_ocf, textvariable=self.pswd_ocf, width=30)
pwentry.focus_set()
pwentry.grid(row=2, column=3, columnspan=2, sticky='w', padx=10)
pwentry.config(show='*')
pswdlabel = ttk.Label(self.passwd_window_ocf, text='Password:')
pswdlabel.grid(row=2, column=2, sticky='e', padx=10)
confirm_but = ttk.Button(self.passwd_window_ocf, text='Confirm', command=self.pwconfirm_ocf)
confirm_but.grid(row=3, column=4, sticky='w', padx=5)
clear_but = ttk.Button(self.passwd_window_ocf, text='Clear',
command=lambda: pwentry.delete(0, Tkinter.END))
clear_but.grid(row=3, column=3, sticky='e', padx=5)
self.passwd_window_ocf.bind('<Return>', self.shortcut3)
def start_cas(self):
# add log in pop up here to let the user to input the username and password. Save then in cas_usr and cas_pw
self.login_window = Tkinter.Toplevel(root)
self.login_window.title('Cassandra Log in')
self.login_window.lift()
x = self.frame3.winfo_rootx()
y = self.frame3.winfo_rooty()
self.login_window.geometry('300x170+%d+%d' % (x+150, y+100))
self.login_window.rowconfigure(0, weight=1)
self.login_window.rowconfigure(1, weight=1)
self.login_window.rowconfigure(2, weight=1)
self.login_window.rowconfigure(3, weight=1)
self.login_window.rowconfigure(4, weight=1)
self.login_window.columnconfigure(0, weight=1)
self.login_window.columnconfigure(1, weight=1)
self.login_window.columnconfigure(2, weight=1)
self.login_window.columnconfigure(3, weight=1)
self.login_window.resizable(False, False)
unlabel = ttk.Label(self.login_window, text='Username:')
unlabel.grid(row=1, column=1)
pwlabel = ttk.Label(self.login_window, text='Password:')
pwlabel.grid(row=2, column=1)
self.username_cas = Tkinter.StringVar()
self.password_cas = Tkinter.StringVar()
unentry = ttk.Entry(self.login_window, textvariable=self.username_cas, width=20)
unentry.focus_set()
unentry.grid(row=1, column=2)
pwentry = ttk.Entry(self.login_window, textvariable=self.password_cas, width=20)
pwentry.grid(row=2, column=2)
pwentry.configure(show='*')
conf_but = ttk.Button(self.login_window, text='Confirm', command=self.checkuser)
conf_but.grid(row=3, column=2, sticky='e')
self.login_window.bind('<Return>', self.shortcut2)
def add_results(self):
try:
self.results_images = self.q.get(0)
self.search_progress.pack_forget()
self.search_progress.destroy()
self.cancel.pack_forget()
self.cancel.destroy()
if self.results_images == 0:
self.reset()
elif self.results_images == -1: # If the URL is invalid
self.error = ttk.Label(self.mainframe, text='Error: Invalid URL', font=self.font, foreground='#ff0000')
self.error.pack() # Create an error message
self.enable_search() # Enable the search option again
elif self.results_images == -2:
self.error = ttk.Label(self.mainframe, text='Error: Network error', font=self.font, foreground='#ff0000')
self.error.pack() # Create an error message
self.enable_search() # Enable the search option again
else:
self.enable_search()
self.results = self.results_images[0]
self.images = self.results_images[1]
self.results_frame = ttk.Frame(self.mainframe)
self.results_label = ttk.Label(self.mainframe, text='Results:', font=self.font)
self.results_label.pack()
for i, result in enumerate(self.results):
text = '%s\n%s\n%s' % (result[0], result[1], result[2])
self.result = ttk.Button(self.results_frame, text=text, image=self.images[i], compound=TOP, command=partial(self.download, i))
self.result.grid(column=i%4, row=i/4)
self.results_frame.pack()
self.create_custom_frame()
except Queue.Empty:
self.master.after(100, self.add_results)
def setUp(self):
support.root_deiconify()
self.widget = ttk.Button(width=0, text="Text")
self.widget.pack()
self.widget.wait_visibility()
def test_invoke(self):
success = []
btn = ttk.Button(command=lambda: success.append(1))
btn.invoke()
self.assertTrue(success)
def create_control_panel(self):
frame=Tkinter.LabelFrame(self.root)
frame.pack(expand='yes',fill='x',side='top')
add_fileicon=Tkinter.PhotoImage(file="../Icons/add_file.gif")
add_directoryicon=Tkinter.PhotoImage(file="../Icons/add_directory.gif")
exiticon=Tkinter.PhotoImage(file="../Icons/exit.gif")
playicon=Tkinter.PhotoImage(file="../Icons/play.gif")
pauseicon=Tkinter.PhotoImage(file="../Icons/pause.gif")
stopicon=Tkinter.PhotoImage(file="../Icons/stop.gif")
rewindicon=Tkinter.PhotoImage(file="../Icons/rewind.gif")
fast_forwardicon=Tkinter.PhotoImage(file="../Icons/fast_forward.gif")
previous_trackicon=Tkinter.PhotoImage(file="../Icons/previous_track.gif")
next_trackicon=Tkinter.PhotoImage(file="../Icons/next_track.gif")
self.muteicon=Tkinter.PhotoImage(file="../Icons/mute.gif")
self.unmuteicon=Tkinter.PhotoImage(file="../Icons/unmute.gif")
delete_selectedicon=Tkinter.PhotoImage(file="../Icons/delete_selected.gif")
list_file=[
(playicon,'self.play'),
(pauseicon,'self.pause'),
(stopicon,'self.stop'),
(previous_trackicon,'self.previous'),
(rewindicon,'self.rewind'),
(fast_forwardicon,'self.fast'),
(next_trackicon,'self.Next'),]
for i,j in list_file:
storeobj=ttk.Button(frame, image=i,command=eval(j))
storeobj.pack(side='left')
storeobj.image=i
self.volume_label=Tkinter.Button(frame,image=self.unmuteicon)
self.volume_label.image=self.unmuteicon
volume=ttk.Scale(frame,from_=Volume_lowest_value, to=Volume_highest_value ,variable=self.var, command=self.update_volume)
volume.pack(side='right', padx=10, )
self.volume_label.pack(side='right')
return
def make_progress_frame_entry(self, label_text, video):
# +-------------------------------------------------+
# | *Titel* start/pause] [cancel] |
# | progress |
# +-------------------------------------------------+
video['progress'] = tk.StringVar()
video['progress'].set('Nog niet gestart')
frame = ttk.Frame(self.progress_frame, relief=tk.GROOVE, borderwidth=10)
video['frame'] = frame
print(video['row'])
frame.grid(row=video['row'], sticky=tk.W + tk.E + tk.N, column=0)
# paned.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
title = tk.Label(frame, text=label_text)
title.grid(row=0, column=0, sticky=tk.W)
video['start_pause'] = tk.StringVar()
video['start_pause'].set('Start')
btn = ttk.Button(frame, textvariable=video['start_pause'], style='Small.TButton',
command=lambda: self.start_or_pause_video(video))
btn.grid(row=0, column=1, sticky=tk.E)
cancel = ttk.Button(frame, text='Annuleren', style='Small.TButton',
command=lambda: self.cancel_video(video))
cancel.grid(row=0, column=2, sticky=tk.E)
progress = tk.Label(frame, textvariable=video['progress'])
progress.grid(row=1, column=0, sticky=tk.W)
def __init__(self, parent=None):
self.parent = parent
tk.Toplevel.__init__(self)
#self.win = tk.Toplevel(parent)
self.iconbitmap(iconloc)
self.title('Busy')
self.resizable(False, False)
self.message = ttk.Label(self, text='Please wait. This may take a long time.')
self.message.grid(column = 0, row=0, sticky = tk.N, padx=5, pady=5)
self.prog = ttk.Progressbar(self, mode = 'indeterminate', orient=tk.HORIZONTAL, maximum=30)
self.prog.grid(column=0, row=1, sticky=(tk.E, tk.W), padx=5, pady=5)
tip = ttk.Label(self, text='[Tip: Perhaps a good time for a coffee?]')
tip.grid(column=0, row=2, sticky=tk.S, padx=5, pady=5)
#self.cancel = ttk.Button(self, text='Cancel', command=self.cancel)
#self.cancel.grid(column=0, row=2, pady=5)