当前位置: 首页>>代码示例>>Python>>正文


Python tkinter.Button方法代码示例

本文整理汇总了Python中tkinter.Button方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.Button方法的具体用法?Python tkinter.Button怎么用?Python tkinter.Button使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter的用法示例。


在下文中一共展示了tkinter.Button方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: popup

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def popup(self, window, title, image, text, button_text, end_command=None):
        popup = tk.Toplevel(window)
        popup.resizable(False, False)
        if MAIN_ICON != None:
            if os.path.splitext(MAIN_ICON)[1].lower() == ".gif":
                dummy = None
                #popup.call('wm', 'iconphoto', popup._w, tk.PhotoImage(file=MAIN_ICON))
            else:
                popup.iconbitmap(MAIN_ICON)
        popup.wm_title(title)
        popup.tkraise(window)

        def run_end():
            popup.destroy()
            if end_command != None:
                end_command()

        picture_label = tk.Label(popup, image=image)
        picture_label.photo = image
        picture_label.grid(column=0, row=0, rowspan=2, padx=10, pady=10)
        tk.Label(popup, text=text, justify=tk.CENTER).grid(column=1, row=0, padx=10, pady=10)
        tk.Button(popup, text=button_text, command=run_end).grid(column=1, row=1, padx=10, pady=10)
        popup.wait_visibility()
        popup.grab_set()
        popup.wait_window() 
开发者ID:nimaid,项目名称:LPHK,代码行数:27,代码来源:window.py

示例2: video_invite_window

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def video_invite_window(message, inviter_name):
    invite_window = tkinter.Toplevel()
    invite_window.geometry('300x100')
    invite_window.title('Invitation')
    label1 = tkinter.Label(invite_window, bg='#f0f0f0', width=20, text=inviter_name)
    label1.pack()
    label2 = tkinter.Label(invite_window, bg='#f0f0f0', width=20, text='invites you to video chat!')
    label2.pack()

    def accept_invite():
        invite_window.destroy()
        video_accept(message[message.index('INVITE') + 6:])

    def refuse_invite():
        invite_window.destroy()

    Refuse = tkinter.Button(invite_window, text="Refuse", command=refuse_invite)
    Refuse.place(x=60, y=60, width=60, height=25)
    Accept = tkinter.Button(invite_window, text="Accept", command=accept_invite)
    Accept.place(x=180, y=60, width=60, height=25) 
开发者ID:11ze,项目名称:The-chat-room,代码行数:22,代码来源:client-test2.py

示例3: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def __init__(self, master=None, store_name=None, **kwargs):
        super(FileBrowse, self).__init__(master=master, **kwargs)
        self.label_text = tk.StringVar()
        btn = tk.Button(self, text="下载到", command=self.choose_file)
        btn.pack(
            side=tk.LEFT,
        )

        tk.Label(self, textvariable=self.label_text).pack(
            side=tk.LEFT,
            fill=tk.X,
        )
        self.pack(fill=tk.X)

        self._store_name = store_name
        if store_name is not None:
            self._config = config_store
            save_path = self._config.op_read_path(store_name) or get_working_dir()
        else:
            self._config = None
            save_path = get_working_dir()

        self.label_text.set(
            save_path
        ) 
开发者ID:winkidney,项目名称:PickTrue,代码行数:27,代码来源:toolkit.py

示例4: build_buttons

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def build_buttons(self):
        btn_args = dict(
            height=1,
        )
        btn_group = tk.Frame(self)

        buttons = [
            tk.Button(
                btn_group,
                text=text,
                command=command,
                **btn_args
            )
            for text, command in (
                ("开始下载", self.start_download),
                ("停止下载", self.stop_download),
                ("打开下载文件夹", self.open_download_folder),
            )
        ]

        for index, btn in enumerate(buttons):
            btn.grid(column=index, row=0, sticky=tk.N)

        btn_group.pack(fill=tk.BOTH, expand=1)
        return btn_group 
开发者ID:winkidney,项目名称:PickTrue,代码行数:27,代码来源:downloader.py

示例5: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def __init__(self):
        super().__init__()
        self.title("Blackjack")
        self.geometry("800x640")
        self.resizable(False, False)

        self.bottom_frame = tk.Frame(self, width=800, height=140, bg="red")
        self.bottom_frame.pack_propagate(0)

        self.hit_button = tk.Button(self.bottom_frame, text="Hit", width=25, command=self.hit)
        self.stick_button = tk.Button(self.bottom_frame, text="Stick", width=25, command=self.stick)

        self.next_round_button = tk.Button(self.bottom_frame, text="Next Round", width=25, command=self.next_round)
        self.quit_button = tk.Button(self.bottom_frame, text="Quit", width=25, command=self.destroy)

        self.new_game_button = tk.Button(self.bottom_frame, text="New Game", width=25, command=self.new_game)

        self.bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)

        self.game_screen = GameScreen(self, bg="white", width=800, height=500)
        self.game_screen.pack(side=tk.LEFT, anchor=tk.N)
        self.game_screen.setup_opening_animation() 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:24,代码来源:ch4.py

示例6: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def __init__(self):
        super().__init__()
        self.title("Hello Tkinter")
        self.label_text = tk.StringVar()
        self.label_text.set("My Name Is: ")

        self.name_text = tk.StringVar()

        self.label = tk.Label(self, textvar=self.label_text)
        self.label.pack(fill=tk.BOTH, expand=1, padx=100, pady=10)

        self.name_entry = tk.Entry(self, textvar=self.name_text)
        self.name_entry.pack(fill=tk.BOTH, expand=1, padx=20, pady=20)

        hello_button = tk.Button(self, text="Say Hello", command=self.say_hello)
        hello_button.pack(side=tk.LEFT, padx=(20, 0), pady=(0, 20))

        goodbye_button = tk.Button(self, text="Say Goodbye", command=self.say_goodbye)
        goodbye_button.pack(side=tk.RIGHT, padx=(0, 20), pady=(0, 20)) 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:21,代码来源:ch1-6.py

示例7: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def __init__(self, main_window, msg='Please enter a node:'):
        tk.Toplevel.__init__(self)
        self.main_window = main_window
        self.title('Node Entry')
        self.geometry('170x160')
        self.rowconfigure(3, weight=1)

        tk.Label(self, text=msg).grid(row=0, column=0, columnspan=2,
                                      sticky='NESW',padx=5,pady=5)
        self.posibilities = [d['dataG_id'] for n,d in
                    main_window.canvas.dispG.nodes_iter(data=True)]
        self.entry = AutocompleteEntry(self.posibilities, self)
        self.entry.bind('<Return>', lambda e: self.destroy(), add='+')
        self.entry.grid(row=1, column=0, columnspan=2, sticky='NESW',padx=5,pady=5)

        tk.Button(self, text='Ok', command=self.destroy).grid(
            row=3, column=0, sticky='ESW',padx=5,pady=5)
        tk.Button(self, text='Cancel', command=self.cancel).grid(
            row=3, column=1, sticky='ESW',padx=5,pady=5)

        # Make modal
        self.winfo_toplevel().wait_window(self) 
开发者ID:jsexauer,项目名称:networkx_viewer,代码行数:24,代码来源:viewer.py

示例8: record_result

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def record_result(self, smile=True):
        print "Image", self.index + 1, ":", "Happy" if smile is True else "Sad"
        self.results[str(self.index)] = smile



# ===================================
# Callback function for the buttons
# ===================================
## smileCallback()              : Gets called when "Happy" Button is pressed
## noSmileCallback()            : Gets called when "Sad" Button is pressed
## updateImageCount()           : Displays the number of images processed
## displayFace()                : Gets called internally by either of the button presses
## displayBarGraph(isBarGraph)  : computes the bar graph after classification is completed 100%
## _begin()                     : Resets the Dataset & Starts from the beginning
## _quit()                      : Quits the Application
## printAndSaveResult()         : Save and print the classification result
## loadResult()                 : Loading the previously stored classification result
## run_once(m)                  : Decorator to allow functions to run only once 
开发者ID:its-izhar,项目名称:Emotion-Recognition-Using-SVMs,代码行数:21,代码来源:Emotion Recognition.py

示例9: ui

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def ui():
    root = tkinter.Tk()
    root.title('PDF和照片互转器')  # 标题
    root.resizable(width=False, height=False)  # 防止大小调整
    canvas = tkinter.Canvas(root, width=450, height=320, highlightthickness=0)  # 创建画布
    photo = tkinter.PhotoImage(file=file_zip_path + os.sep + 'pdf.png')  # 获取背景图片的网络连接
    canvas.create_image(225, 160, image=photo)

    select_dir_button = tkinter.Button(root, text="选择照片文件夹", command=select_dir, bg='yellow')  # 创建按钮
    select_pdf_button = tkinter.Button(root, text="选择PDF文件", command=select_pdf, bg='green')
    click_button = tkinter.Button(root, text="点击执行", command=start, bg='blue')

    select_dir_button.pack()  # 启动按钮
    select_pdf_button.pack()
    click_button.pack()

    canvas.create_window(240, 120, width=100, height=30, window=select_dir_button)  # 将按钮创建到画布
    canvas.create_window(240, 190, width=100, height=30, window=select_pdf_button)
    canvas.create_window(240, 260, width=100, height=30, window=click_button)
    canvas.pack()  # 启动画布
    root.mainloop()  # 主程序循环 
开发者ID:jtyoui,项目名称:Jtyoui,代码行数:23,代码来源:tk.py

示例10: add_attr

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def add_attr(self, attr_name, right_label_text=None, *args):
        '''Add attr to the lower frame with a '-' button & title
        
        attr_name: title to be shown on the left side
        right_label_text: label string to be shown on the right side, which is
                          a word count or 'Calculating...'
        '''
        if len(self.attrs) == 0:
            self.lower_frame = Frame(self)
            self.lower_frame.pack(side="bottom", fill="both")
        attr = LabeledFrame(self.lower_frame, title=attr_name)
        btn_add_file = Tk.Button(attr, text=' - ')
        btn_add_file.pack(fill="both", side="left", padx=10, pady=5)
        btn_add_file.bind("<ButtonRelease-1>", partial(self.on_remove_attr, attr))
        lb_base_files = Tk.Label(attr, text=attr_name)
        lb_base_files.pack(fill="both", side="left", padx=10, pady=10)
        
        if right_label_text is not None:
            attr.right_label = Tk.Label(attr, text=right_label_text, font=('Helvetica', '10', 'italic'))
            attr.right_label.pack(fill="both", side="right", padx=10, pady=10)
        else:
            attr.right_label = None
        
        attr.pack(side="top", fill="both")
        self.attrs.append(attr) 
开发者ID:sc0tfree,项目名称:mentalist,代码行数:27,代码来源:base.py

示例11: __init__

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def __init__(self, root, main_window, button_opt):
        ttk.Frame.__init__(self, root)
        
        self.root = root
        self.main_window = main_window
        self.current_files = None
        self.button_opt = button_opt
        
        # define options for opening or saving a file
        self.file_opt = options = {}
        options['defaultextension'] = '.txt'
        options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
        options['initialdir'] = os.path.expanduser("~")
        options['parent'] = root
        options['title'] = 'Select files to annotate.'
        
        self.file_selector_button = ttk.Button(self.root, text=u"select file(s)", command=self.filenames)
        self.label = ttk.Label(self.root, text=u"selected file(s):")
        self.fa_search = tkinter.PhotoImage(file=os.path.join(self.main_window.resource_dir, "images", "fa_search_24_24.gif"))
        self.file_selector_button.config(image=self.fa_search, compound=tkinter.LEFT)
        
        self.scrollbar = ttk.Scrollbar(self.root)
        self.selected_files = tkinter.Listbox(self.root, yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.selected_files.yview) 
开发者ID:YoannDupont,项目名称:SEM,代码行数:26,代码来源:components.py

示例12: addLine

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def addLine(self, settingsList, dpsFrame):
        lineNumber = len(settingsList)
        settingsList.append({"transitionValue": "", "color": "#FFFFFF"})
        settingsList[lineNumber]["transitionValue"] = tk.StringVar()
        settingsList[lineNumber]["transitionValue"].set(str(100*lineNumber))
              
        removeButton = tk.Button(dpsFrame, text="X", command=lambda:self.removeLine(lineNumber, settingsList, dpsFrame))
        font = tkFont.Font(font=removeButton['font'])
        font.config(weight='bold')
        removeButton['font'] = font
        removeButton.grid(row=lineNumber, column="0")
        lineLabel = tk.Label(dpsFrame, text="Threshold when the line changes color:")
        lineLabel.grid(row=lineNumber, column="1")
        initialThreshold = tk.Entry(dpsFrame, textvariable=settingsList[lineNumber]["transitionValue"], width=10)
        initialThreshold.grid(row=lineNumber, column="2")
        initialLabel = tk.Label(dpsFrame, text="Color:")
        initialLabel.grid(row=lineNumber, column="3")
        colorButton = tk.Button(dpsFrame, text="    ", 
                                command=lambda:self.colorWindow(settingsList[lineNumber], colorButton), 
                                bg=settingsList[lineNumber]["color"])
        colorButton.grid(row=lineNumber, column="4") 
开发者ID:ArtificialQualia,项目名称:PyEveLiveDPS,代码行数:23,代码来源:lineSettingsFrame.py

示例13: create_inputs

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def create_inputs(self):
    settings = list(self.camera.settings_dict.keys())
    settings.sort(key=lambda e: str(type(self.camera.settings[e].limits)))
    self.scales = {}
    self.radios = {}
    self.checks = {}
    i = 0
    for i,k in enumerate(settings):
      s = self.camera.settings[k]
      if type(s.limits) == tuple:
        self.create_scale(s,i)
      elif type(s.limits) == bool:
        self.create_check(s,i)
      elif type(s.limits) == dict:
        self.create_radio(s,i)
    self.lower_frame = tk.Frame()
    self.lower_frame.grid(column=1,row=i+3)
    self.apply_button = tk.Button(self.lower_frame,text="Apply",
                                  command=self.apply_settings)
    self.apply_button.pack()
    #self.apply_button.grid(column=1,row=i+3) 
开发者ID:LaboratoireMecaniqueLille,项目名称:crappy,代码行数:23,代码来源:cameraConfig.py

示例14: ask_color

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def ask_color(self, window, button, x, y, default_color):
        global colors_to_set
        
        if lp_mode == "Mk1":
            color = self.classic_askcolor(color=tuple(default_color), title="Select Color for Button (" + str(x) + ", " + str(y) + ")")
        else:
            color = tkcolorpicker.askcolor(color=tuple(default_color), parent=window, title="Select Color for Button (" + str(x) + ", " + str(y) + ")")
        if color[0] != None:
            color_to_set = [int(min(255, max(0, c))) for c in color[0]]
            if all(c < 4 for c in color_to_set):
                rerun = lambda: self.ask_color(window, button, x, y, default_color)
                self.popup(window, "Invalid Color", self.warning_image, "That color is too dark to see.", "OK", rerun)
            else:
                colors_to_set[x][y] = color_to_set
                self.button_color_with_text_update(button, color[1]) 
开发者ID:nimaid,项目名称:LPHK,代码行数:17,代码来源:window.py

示例15: express

# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Button [as 别名]
def express():
    global b1, b2, b3, b4, ee
    if ee == 0:
        ee = 1
        b1 = tkinter.Button(root, command=bb1, image=p1,
                            relief=tkinter.FLAT, bd=0)
        b2 = tkinter.Button(root, command=bb2, image=p2,
                            relief=tkinter.FLAT, bd=0)
        b3 = tkinter.Button(root, command=bb3, image=p3,
                            relief=tkinter.FLAT, bd=0)
        b4 = tkinter.Button(root, command=bb4, image=p4,
                            relief=tkinter.FLAT, bd=0)

        b1.place(x=5, y=248)
        b2.place(x=75, y=248)
        b3.place(x=145, y=248)
        b4.place(x=215, y=248)
    else:
        ee = 0
        b1.destroy()
        b2.destroy()
        b3.destroy()
        b4.destroy()


# 创建表情按钮 
开发者ID:11ze,项目名称:The-chat-room,代码行数:28,代码来源:client-test2.py


注:本文中的tkinter.Button方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。