本文整理汇总了Python中tkinter.Button类的典型用法代码示例。如果您正苦于以下问题:Python Button类的具体用法?Python Button怎么用?Python Button使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Button类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CircleBuilderPopup
class CircleBuilderPopup(BuilderPopup):
"""
Class that launches a popup and collects user data to pass data back to the main window
to build a circle.
"""
def __init__(self, master):
"""
Establish the GUI of this popup
"""
BuilderPopup.__init__(self, master)
self.data = (0, 0)
self.radius = Label(self.top, text="Radius")
self.radius_entry = Entry(self.top, width=self.width, bd=self.bd)
self.center = Label(self.top, text="Center")
self.center_entry = Entry(self.top, width=self.width, bd=self.bd)
self.build_circle_submit = Button(self.top, text="Build!", command=self.cleanup)
self.top.bind("<Return>", self.cleanup)
self.radius.grid(row=0, column=0)
self.radius_entry.grid(row=0, column=1)
self.center.grid(row=1, column=0)
self.center_entry.grid(row=1, column=1)
self.build_circle_submit.grid(row=2, column=0, columnspan=2)
self.top_left = 0
self.bottom_right = 0
self.radius_entry.focus()
def cleanup(self, entry=None):
"""
Collect the data from the user and package it into object variables, then close.
"""
center = complex(0, 0)
if self.center_entry.get():
center = complex(allow_constants(self.center_entry.get()))
self.data = (float(allow_constants(self.radius_entry.get())), center)
self.top.destroy()
示例2: Demo
class Demo(Frame):
def __init__(self, parent, *args, **kw):
Frame.__init__(self, parent, *args,**kw)
self.e=Entry(self, text='Message')
self.e.delete(0,'end')
self.e.pack()
self.makebuttons()
self.pack(expand='true',fill='x')
def makebuttons(self):
self.b1=Button(self, text="restart",bg="blue",fg='white',command= self.restart )
self.b1.pack(side='right',fill='both' )
self.b2=Button(self,text='quit',bg='green',fg='white',command=self.quit)
self.b2.pack(side='left',fill='both')
self.lastTime=""
self.start_timer()
def start_timer(self):
pass
def destroy(self):
self.pack_forget()
def restart(self):
self.destroy()
D=Demo(root,bg='purple')
print ("killed")
D.__init__(self,root)
pass
def quit(self):
root.destroy()
示例3: create_toolbar
def create_toolbar(self):
self.toolbar = Frame(self.parent)
self.btn_new = Button(self.toolbar, text='New', command=self.new_file)
self.btn_new.grid(row=0, column=0)
self.btn_open = Button(self.toolbar, text='Open', command=self.open_file)
self.btn_open.grid(row=0, column=1)
self.toolbar.pack(fill='both')
示例4: __init__
def __init__(self, client):
# Basic setup
super(Preferences, self).__init__()
self.client = client
# Setup the variables used
self.echo_input = BooleanVar()
self.echo_input.set(self.client.config['UI'].getboolean('echo_input'))
self.echo_input.trace("w", self.echo_handler)
self.logging = BooleanVar()
self.logging.set(self.client.config['logging'].getboolean('log_session'))
self.logging.trace('w', self.logging_handler)
self.log_dir = self.client.config['logging']['log_directory']
# Build the actual window and widgets
prefs = Toplevel(self)
prefs.wm_title("Preferences")
echo_input_label = Label(prefs, text="Echo Input:")
logging_label = Label(prefs, text='Log to file:')
echo_checkbox = Checkbutton(prefs, variable=self.echo_input)
logging_checkbox = Checkbutton(prefs, variable=self.logging)
logging_button_text = 'Choose file...' if self.log_dir == "" else self.log_dir
logging_button = Button(prefs, text=logging_button_text, command=self.logging_pick_location)
# Pack 'em in.
echo_input_label.grid(row=0, column=0)
echo_checkbox.grid(row=0, column=1)
logging_label.grid(row=1, column=0)
logging_checkbox.grid(row=1, column=1)
logging_button.grid(row=1, column=2)
示例5: __init__
def __init__(self, master=None):
# Avoiding to send it continuously.
self.lock = False
Frame.__init__(self, master)
self.grid()
self.master = master
# Setting for ComboBox.
self.url_lang_combobox_str = StringVar()
self.url_lang_combobox_list = lang_list
# UI components.
self.receiver_email_text = Label(self, text="Receiver:")
self.receiver_email_field = Entry(self, width=50)
self.subject_text = Label(self, text='Subject:')
self.subject_field = Entry(self, width=50)
self.receiver_name_text = Label(self, text='Name:')
self.receiver_name_field = Entry(self, width=50)
self.url_lang_text = Label(self, text='Link lang:')
self.url_lang_combobox = Combobox(self, textvariable=self.url_lang_combobox_str, values=self.url_lang_combobox_list, state='readonly')
self.send_progressbar = Progressbar(self, orient='horizontal', length=500, mode='determinate', maximum=300)
self.send_button = Button(self, text='Send', command=self._send_mail)
self.quit_button = Button(self, text='Exit', command=self.__exit)
self.log_msg_text = ScrolledText(self)
# Attachment.
self.mail_attachment_list = attachment_list[:]
self.url_lang_link_title = None
self.url_lang_link = copy.deepcopy(content_link)
# Mailer
self._mailer = None
# Let Mailer can control components.
Mailer.window_content = self
self.__create_widgets()
示例6: Application
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(sticky=N+S+E+W)
self.mainframe()
def mainframe(self):
self.data = Listbox(self, bg='red')
self.scrollbar = Scrollbar(self.data, orient=VERTICAL)
self.data.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.data.yview)
for i in range(1000):
self.data.insert(END, str(i))
self.run = Button(self, text="run")
self.stop = Button(self, text="stop")
self.data.grid(row=0, column=0, rowspan=4,
columnspan=2, sticky=N+E+S+W)
self.data.columnconfigure(0, weight=1)
self.run.grid(row=4,column=0,sticky=EW)
self.stop.grid(row=4,column=1,sticky=EW)
self.scrollbar.grid(column=2, sticky=N+S)
示例7: make_button
def make_button(self, label, command, isdef=0):
"Return command button gridded in command frame."
b = Button(self.buttonframe, text=label, command=command, default=isdef and "active" or "normal")
cols, rows = self.buttonframe.grid_size()
b.grid(pady=1, row=rows, column=0, sticky="ew")
self.buttonframe.grid(rowspan=rows + 1)
return b
示例8: __init__
def __init__(self, master, line_collection):
try:
self.width_of_entry = len(line_collection[0])
except IndexError:
self.width_of_entry = 0
self.top = Toplevel(master)
self.current_lines_listbox = Listbox(self.top)
self.removed_lines_listbox = Listbox(self.top)
self.submit = Button(self.top, text = "Ok", command=self.submit)
self.remove_button = Button(self.top, text = "Remove", command=self.remove_line)
self.cancel = Button(self.top, text = "Cancel", command=self.top.destroy)
self.top.bind("<Return>", func=self.submit)
self.current_lines = line_collection
self.removed_lines = []
self.ids_internal = []
self.ids = []
for index, line in enumerate(self.current_lines):
#removes the point data and converts the rest to strings
id = line[1]
if id not in self.ids_internal:
self.ids_internal.append(id)
self.ids.append(id)
line = [str(element) for element in line[1:]]
#put into the list
self.current_lines_listbox.insert(index, " ".join(line))
self.current_lines_listbox.grid(row=0, column=0, columnspan=3)
self.submit.grid(row=1, column=1)
self.cancel.grid(row=1, column=2)
self.remove_button.grid(row=1, column=0)
示例9: __init__
def __init__(self, master):
self.master = master
master.title("Calculator")
self.total = 0
self.entered_number = 0
self.total_label_text = IntVar()
self.total_label_text.set(self.total)
self.total_label = Label(master, textvariable=self.total_label_text)
self.label = Label(master, text="Total:")
vcmd = master.register(self.validate) # we have to wrap the command
self.entry = Entry(master, validate="key", validatecommand=(vcmd, "%P"))
self.add_button = Button(master, text="+", command=lambda: self.update("add"))
self.subtract_button = Button(master, text="-", command=lambda: self.update("subtract"))
self.multiply_button = Button(master, text="*", command=lambda: self.update("multiply"))
# self.divide_button = Button(master, text="/", command=lambda: self.update("divide"))
self.reset_button = Button(master, text="Reset", command=lambda: self.update("reset"))
# LAYOUT
self.label.grid(row=0, column=0, sticky=W)
self.total_label.grid(row=0, column=1, columnspan=2, sticky=E)
self.entry.grid(row=1, column=0, columnspan=5, sticky=W + E)
self.add_button.grid(row=2, column=0)
self.subtract_button.grid(row=2, column=1)
self.multiply_button.grid(row=2, column=2)
# self.divide_button.grid(row=2, column=3)
self.reset_button.grid(row=2, column=4, sticky=W + E)
示例10: __init__
def __init__(self, method=None, master=None):
self.method = method
self.picframe = Frame.__init__(self, master)
self.master.title("Robobackup")
self.image = PhotoImage()
self.image["file"] = os.path.join(os.path.dirname(\
os.path.relpath(__file__)), "resources", "ASK.png")
self.piclabel = Label(self.picframe, image=self.image)
self.piclabel.grid(row=0, column=0, columnspan=4, rowspan=6)
self.clocklabel = Label(self.picframe, text=_("Elapsed time:"))
self.clocklabel.grid(row=0, column=4, sticky="NSEW")
self.clock = Label(self.picframe, text="")
self.clock.grid(row=1, column=4, sticky="NSEW")
self.start = Button(self.picframe, text=_("Start Backup"), command=self.__clk)
self.start.grid(row=3, column=4, sticky="NSEW")
self.errorlabel = Label(self.picframe)
self.errorlabel.grid(row=4, column=4, sticky="NSEW")
self.close = Button(self.picframe, text=_("Close"), command=self.__cls)
self.close.grid(row=5, column=4, sticky="NSEW")
self.loglabel = Label(self.picframe, text=_("Log:"), justify="left")
self.loglabel.grid(row=6, column=0, columnspan=5, sticky="NSEW")
self.text = Text(self.picframe)
self.text.grid(row=7, column=0, rowspan=6, columnspan=5, sticky="NSEW")
self.timeout = False
self.starttime = -1
示例11: create_monitor
def create_monitor(self):
self.monitor_frame = LabelFrame(self, text="Monitor and Transport")
this_cycle = Scale(self.monitor_frame, label='cycle_pos', orient=HORIZONTAL,
from_=1, to=16, resolution=1)
this_cycle.disable, this_cycle.enable = (None, None)
this_cycle.ref = 'cycle_pos'
this_cycle.grid(column=0, row=0, sticky=E + W)
self.updateButton = Button(self.monitor_frame,
text='Reload all Settings',
command=self.request_update)
self.updateButton.grid(row=1, sticky=E + W)
self.ForceCaesuraButton = Button(self.monitor_frame,
text='Force Caesura',
command=self.force_caesura)
self.ForceCaesuraButton.grid(row=2, sticky=E + W)
self.saveBehaviourButton = Button(self.monitor_frame,
text='Save current behaviour',
command=self.request_saving_behaviour)
self.saveBehaviourButton.grid(row=3, sticky=E + W)
self.saveBehaviourNameEntry = Entry(self.monitor_frame)
self.saveBehaviourNameEntry.grid(row=4, sticky=E + W)
self.saveBehaviourNameEntry.bind('<KeyRelease>', self.request_saving_behaviour)
self.selected_behaviour = StringVar()
self.selected_behaviour.trace('w', self.new_behaviour_chosen)
self.savedBehavioursMenu = OptionMenu(self.monitor_frame,
self.selected_behaviour, None,)
self.savedBehavioursMenu.grid(row=5, sticky=E + W)
self.monitor_frame.grid(column=0, row=10, sticky=E + W)
示例12: Example
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("test")
self.pack(fill=BOTH, expand=1)
self.cal = Button(self)
self.cal["text"] = "Calculate"
self.cal["command"] = self.cal_frequency
self.cal.pack(fill=BOTH, expand=1)
def cal_frequency(self):
# use the dialog to find the route of the file
file_path = filedialog.askopenfilename()
frequency = [ 0 for i in range(26)]
f = open(file_path, 'r')
article = f.read()
for i in article:
seq = alpha_to_num(i)
if seq != -1:
frequency[seq] += 1
print (frequency)
示例13: __init__
def __init__(self, parent):
# super(createSets,self).__init__(parent)
Frame.__init__(self, parent)
self.parent = parent
self.grid(row=0, column=0)
self.parentWindow = 0
self.listBox = Listbox(self, selectmode=EXTENDED)
self.listBox.grid(row=1, column=1)
for item in ["one", "two", "three", "four"]:
self.listBox.insert(END, item)
self.buttonDel = Button(self,
text="delite selected class",
command=self.del_selected) # lambda ld=self.listBox:ld.delete(ANCHOR))
self.buttonDel.grid(row=0, column=0)
self.entry = Entry(self, state=NORMAL)
# self.entry.focus_set()
self.entry.insert(0, "default")
self.entry.grid(row=1, column=0)
self.buttonInsert = Button(self, text="add new class",
command=self.add)
self.buttonInsert.grid(row=0, column=1)
self.buttonDone = Button(self, text="done", command=self.done)
self.buttonDone.grid(row=2, column=0)
示例14: InfoFrame
class InfoFrame(Frame):
def __init__(self,master=None, thread=None):
Frame.__init__(self, master)
self.controlThread=thread
self.stringVar=StringVar()
self.grid()
self.createWidgets()
def createWidgets(self):
self.inputText=Label(self)
if self.inputText != None:
self.inputText['textvariable']=self.stringVar
self.inputText["width"] = 50
self.inputText.grid(row=0, column=0, columnspan=6)
else:
pass
self.cancelBtn = Button(self, command=self.clickCancelBtn) # need to implement
if self.cancelBtn !=None:
self.cancelBtn["text"] = "Cancel"
self.cancelBtn.grid(row=0, column=6)
else:
pass
def clickCancelBtn(self):
print("close the InfoDialog")
self.controlThread.setStop()
def updateInfo(self, str):
self.stringVar.set(str)
示例15: __init__
class MessageTester:
def __init__(self, root):
root.title("Message tester")
Label(root, text="Enter message event below", bg="light green").pack()
self.event_field = ScrolledText(root, width=180, height=10)
self.event_field.pack()
Label(root, text="Enter test case below", bg="light green").pack()
self.test_case_field = ScrolledText(root, width=180, height=20)
self.test_case_field.pack()
Label(root, text="Test result:", bg="light green").pack()
self.result_field = ScrolledText(root, width=180, height=10)
self.result_field.pack()
self.result_field.config(state=DISABLED)
self.button = Button(root, text="Evaluate", fg="red",
command=self._clicked)
self.button.pack()
self.event_field.delete('1.0', END)
self.event_field.insert('insert', EXAMPLE_EVENT)
self.test_case_field.delete('1.0', END)
self.test_case_field.insert('insert', EXAMPLE_TEST_CASE)
def _clicked(self):
event = self.event_field.get('1.0', END)
test_case = self.test_case_field.get('1.0', END)
evaluation = skill_tester.EvaluationRule(ast.literal_eval(test_case))
evaluation.evaluate(ast.literal_eval(event))
self.result_field.config(state=NORMAL)
self.result_field.delete('1.0', END)
self.result_field.insert('insert', evaluation.rule)
self.result_field.config(state=DISABLED)