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


Python ttk.Button方法代码示例

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


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

示例1: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)

        self.name = tk.StringVar()
        self.hello_string = tk.StringVar()
        self.hello_string.set("Hello World")

        name_label = ttk.Label(self, text="Name:")
        name_entry = ttk.Entry(self, textvariable=self.name)
        ch_button = ttk.Button(self, text="Change", command=self.on_change)
        hello_label = ttk.Label(self, textvariable=self.hello_string,
            font=("TkDefaultFont", 64), wraplength=600)

        # Layout form
        name_label.grid(row=0, column=0, sticky=tk.W)
        name_entry.grid(row=0, column=1, sticky=(tk.W + tk.E))
        ch_button.grid(row=0, column=2, sticky=tk.E)
        hello_label.grid(row=1, column=0, columnspan=3)
        self.columnconfigure(1, weight=1) 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:21,代码来源:better_hello_tkinter.py

示例2: load_friends

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def load_friends(self):
        all_users = self.requester.get_all_users()

        for user in all_users:
            if user['username'] != self.username:
                friend_frame = ttk.Frame(self.canvas_frame)

                profile_photo = tk.PhotoImage(file="images/avatar.png")
                profile_photo_label = ttk.Label(friend_frame, image=profile_photo)
                profile_photo_label.image = profile_photo

                friend_name = ttk.Label(friend_frame, text=user['real_name'], anchor=tk.W)

                message_this_friend = partial(self.open_chat_window, username=user["username"], real_name=user["real_name"])

                message_button = ttk.Button(friend_frame, text="Chat", command=message_this_friend)

                profile_photo_label.pack(side=tk.LEFT)
                friend_name.pack(side=tk.LEFT)
                message_button.pack(side=tk.RIGHT)

                friend_frame.pack(fill=tk.X, expand=1) 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:24,代码来源:friendslist.py

示例3: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, master, **kwargs):
        super().__init__(**kwargs)
        self.master = master
        self.transient(master)
        self.position_window()

        smilie_files = [file for file in os.listdir(self.smilies_dir) if file.endswith(".png")]

        self.smilie_images = []

        for file in smilie_files:
            full_path = os.path.join(self.smilies_dir, file)
            image = tk.PhotoImage(file=full_path)
            self.smilie_images.append(image)

        for index, file in enumerate(self.smilie_images):
            row, col = divmod(index, 3)
            button = ttk.Button(self, image=file, command=lambda s=file: self.insert_smilie(s))
            button.grid(row=row, column=col, sticky='nsew')

        for i in range(3):
            tk.Grid.columnconfigure(self, i, weight=1)
            tk.Grid.rowconfigure(self, i, weight=1) 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:25,代码来源:smilieselect.py

示例4: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, master):
        super().__init__()

        self.master = master
        self.transient(master)

        self.title("Change Avatar")
        self.geometry("350x200")

        self.image_file_types = [
            ("Png Images", ("*.png", "*.PNG")),
        ]

        self.current_avatar_image = tk.PhotoImage(file=avatar_file_path)

        self.current_avatar = ttk.Label(self, image=self.current_avatar_image)
        choose_file_button = ttk.Button(self, text="Choose File", command=self.choose_image)

        self.current_avatar.pack()
        choose_file_button.pack() 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:22,代码来源:avatarwindow.py

示例5: tagDemo

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def tagDemo(self):
        if self.btn9['text']=='Create tag named \'myTag\' at line 2':
            self.btn9.config(text = 'Remove Tag')
            self.text.tag_add('myTag', '2.0', '2.0 lineend')
            
            self.btn10 = ttk.Button(self.master, text = 'Change myTag background to yellow', command = self.tagbgyellow)
            self.btn10.pack()
            
            self.btn11 = ttk.Button(self.master, text = 'Remove tag from 1st word of line 2', command = self.tagrm21word)
            self.btn11.pack()
            
            self.btn12 = ttk.Button(self.master, text = 'myTag Span', command = self.getTagSpan)
            self.btn12.pack()
            
            self.btn13 = ttk.Button(self.master, text = 'Show all Tags in Text widget', command = self.displayAllTags)
            self.btn13.pack()
            
        else:
            self.btn9.config(text = 'Create tag named \'myTag\' at line 2')
            self.text.tag_delete('myTag')
            self.btn10.destroy()
            self.btn11.destroy()
            self.btn12.destroy()
            self.btn13.destroy() 
开发者ID:adipandas,项目名称:python-gui-demos,代码行数:26,代码来源:program13.py

示例6: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, master):
        self.button = ttk.Button(master, text = 'Click me')
        self.button.pack()
        self.button.config(command = self.buttonfunc)          # configure a command for button click
        
        self.btn1 = ttk.Button(master, text = 'Click on \'Click me\'', command = self.invokebutton)
        self.btn1.pack()
        
        self.btn2 = ttk.Button(master, text = 'Disable \'Click me\'', command = self.disableButton)
        self.btn2.pack()
        
        self.btn3 = ttk.Button(master, text = 'Enable \'Click me\'', command = self.enableButton)
        self.btn3.pack()
        
        self.btn4 = ttk.Button(master, text = 'Query state of \'Click me\'', command = self.queryButtonState)
        self.btn4.pack()
        
        self.button.img  = tk.PhotoImage(file = 'simple_gif.gif')
        self.button.img = self.button.img.subsample(10, 10) # take every 5th pixel in x and y direction of image
        
        self.btn5 = ttk.Button(master, text = 'Add image to \'Click me\'', command = self.addImage)
        self.btn5.pack()
        
        self.label = ttk.Label(master, text = 'No button pressed yet.')
        self.label.pack() 
开发者ID:adipandas,项目名称:python-gui-demos,代码行数:27,代码来源:program4.py

示例7: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, master):     # constructor method
        # define list of label texts
        self.greet_list = ('Hello, World! This is python GUI.', \
                           'Hello, This is Python GUI. Sadly, I was made to say Hello only. I will love to say so much more.')
        
        # creat label as a child of root window with some text.
        self.label = ttk.Label(master, text = self.greet_list[0])
        
        self.btn = ttk.Button(master, text = 'Greet Again', command = self.handle_text) # create a button
        
        # store image in the label obj to keep it in the scope as 
        # long as label is displayed and to avoid getting the image getting garbage collected
        imgpath = 'simple_gif.gif'                                      # path of the image
        self.label.img = tk.PhotoImage(file = imgpath)                  # read_image :: saving image within label_object to prevent its garbage collection
        self.label.config(image = self.label.img)                       # display image in label widget
        self.label.config(compound = 'left')                            # to display image in left of text
        
        self.label.pack()                                               # pack label to the window with pack() geometry method of Label
        self.btn.pack()
        
        self.label.config(wraplength = 200)                             # specify wraplength of text in label
        self.label.config(justify = tk.CENTER)                          # justify text in label to (CENTER, RIGHT or LEFT)
        self.label.config(foreground = 'blue', background = 'yellow')   # insert font color (foreground) and background color
        self.label.config(font = ('Times', 10, 'bold'))                 # font = (font_name, font_size, font_type) 
开发者ID:adipandas,项目名称:python-gui-demos,代码行数:26,代码来源:program3.py

示例8: combineAction

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def combineAction():
    global course_json
    other_course_dir = tk.filedialog.askdirectory(initialdir = ".", title = "Select second course directory")

    if other_course_dir:
        drawPlaceholder()
        course1_json = copy.deepcopy(course_json) # Make copy so this isn't "permanent" in memory
        course2_json = tgc_tools.get_course_json(other_course_dir)

        course1_json = tgc_tools.merge_courses(course1_json, course2_json)
        drawCourse(course1_json)

        popup = tk.Toplevel()
        popup.geometry("400x400")
        popup.wm_title("Confirm course merge?")
        label = ttk.Label(popup, text="Confirm course merge?")
        label.pack(side="top", fill="x", pady=10)
        B1 = ttk.Button(popup, text="Yes, Merge", command = partial(confirmCourse, popup, course1_json))
        B1.pack()
        B2 = ttk.Button(popup, text="No, Abandon Merge", command = partial(confirmCourse, popup, None))
        B2.pack()
        popup.mainloop() 
开发者ID:chadrockey,项目名称:TGC-Designer-Tools,代码行数:24,代码来源:tgc_gui.py

示例9: load_pipeline

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def load_pipeline(self, event=None):
        top = tkinter.Toplevel()
        master_selector = SemTkMasterSelector(top, os.path.join(sem.SEM_DATA_DIR, "resources"))
        lang_selector = SemTkLangSelector(top, os.path.join(sem.SEM_DATA_DIR, "resources"))
        lang_selector.master_selector = master_selector
        vars_cur_row = 0
        vars_cur_row, _ = lang_selector.grid(row=vars_cur_row, column=0)
        vars_cur_row, _ = master_selector.grid(row=vars_cur_row, column=0)
        
        def cancel(event=None):
            if self.pipeline is not None:
                self.tag_document_btn.configure(state=tkinter.NORMAL)
            top.destroy()
        def ok(event=None):
            path = master_selector.workflow()
            pipeline, _, _, _ = sem.modules.tagger.load_master(path)
            self.pipeline = pipeline
            cancel()
        
        ok_btn = ttk.Button(top, text="load workflow", command=ok)
        ok_btn.grid(row=vars_cur_row, column=0)
        cancel_btn = ttk.Button(top, text="cancel", command=cancel)
        cancel_btn.grid(row=vars_cur_row, column=1) 
开发者ID:YoannDupont,项目名称:SEM,代码行数:25,代码来源:annotation_gui.py

示例10: create_toolbar

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def create_toolbar(self):
        self.toolbar = ttk.Frame(self.master)
        newButton = ttk.Button(self.toolbar, text=NEW, takefocus=False,
                image=self.images[NEW], command=self.board.new_game)
        TkUtil.Tooltip.Tooltip(newButton, text="New Game")
        zoomLabel = ttk.Label(self.toolbar, text="Zoom:")
        self.zoomSpinbox = Spinbox(self.toolbar,
                textvariable=self.zoom, from_=Board.MIN_ZOOM,
                to=Board.MAX_ZOOM, increment=Board.ZOOM_INC, width=3,
                justify=tk.RIGHT, validate="all")
        self.zoomSpinbox.config(validatecommand=(
                self.zoomSpinbox.register(self.validate_int), "%P"))
        TkUtil.Tooltip.Tooltip(self.zoomSpinbox, text="Zoom level (%)")
        self.shapeCombobox = ttk.Combobox(self.toolbar, width=8,
                textvariable=self.shapeName, state="readonly",
                values=sorted(Shapes.ShapeForName.keys()))
        TkUtil.Tooltip.Tooltip(self.shapeCombobox, text="Tile Shape")
        TkUtil.add_toolbar_buttons(self.toolbar, (newButton, None,
                zoomLabel, self.zoomSpinbox, self.shapeCombobox))
        self.toolbar.pack(side=tk.TOP, fill=tk.X, before=self.board) 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:22,代码来源:Main.py

示例11: __create_widgets

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __create_widgets(self):
        self.dockFrame = ttk.Frame(self, relief=tk.RAISED, padding=PAD)
        self.dockLeftButton = ttk.Button(self.dockFrame,
                image=self.images[DOCKLEFT], style="Toolbutton",
                command=self.dock_left)
        TkUtil.Tooltip.Tooltip(self.dockLeftButton, text="Dock Left")
        self.dockRightButton = ttk.Button(self.dockFrame,
                image=self.images[DOCKRIGHT], style="Toolbutton",
                command=self.dock_right)
        TkUtil.Tooltip.Tooltip(self.dockRightButton, text="Dock Right")
        self.dockLabel = ttk.Label(self.dockFrame, text=self.title,
                anchor=tk.CENTER)
        TkUtil.Tooltip.Tooltip(self.dockLabel, text="Drag and drop to "
                "dock elsewhere or to undock")
        self.undockButton = ttk.Button(self.dockFrame,
                image=self.images[UNDOCK], style="Toolbutton",
                command=self.undock)
        TkUtil.Tooltip.Tooltip(self.undockButton, text="Undock")
        self.hideButton = ttk.Button(self.dockFrame,
                image=self.images[HIDE], style="Toolbutton",
                command=lambda *args: self.visible.set(False))
        TkUtil.Tooltip.Tooltip(self.hideButton, text="Hide")
        self.create_widgets() 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:25,代码来源:Dock.py

示例12: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, parent, label='', input_class=ttk.Entry,
                 input_var=None, input_args=None, label_args=None,
                 **kwargs):
        super().__init__(parent, **kwargs)
        input_args = input_args or {}
        label_args = label_args or {}
        self.variable = input_var

        if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton):
            input_args["text"] = label
            input_args["variable"] = input_var
        else:
            self.label = ttk.Label(self, text=label, **label_args)
            self.label.grid(row=0, column=0, sticky=(tk.W + tk.E))
            input_args["textvariable"] = input_var

        self.input = input_class(self, **input_args)
        self.input.grid(row=1, column=0, sticky=(tk.W + tk.E))
        self.columnconfigure(0, weight=1)
        self.error = getattr(self.input, 'error', tk.StringVar())
        self.error_label = ttk.Label(self, textvariable=self.error)
        self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E)) 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:24,代码来源:data_entry_app.py

示例13: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.title("ABQ Data Entry Application")
        self.resizable(width=False, height=False)

        ttk.Label(
            self,
            text="ABQ Data Entry Application",
            font=("TkDefaultFont", 16)
        ).grid(row=0)


        self.recordform = v.DataRecordForm(self, m.CSVModel.fields)
        self.recordform.grid(row=1, padx=10)

        self.savebutton = ttk.Button(self, text="Save", command=self.on_save)
        self.savebutton.grid(sticky="e", row=2, padx=10)

        # status bar
        self.status = tk.StringVar()
        self.statusbar = ttk.Label(self, textvariable=self.status)
        self.statusbar.grid(sticky="we", row=3, padx=10)

        self.records_saved = 0 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:27,代码来源:application.py

示例14: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.title("ABQ Data Entry Application")
        self.resizable(width=False, height=False)

        ttk.Label(
            self,
            text="ABQ Data Entry Application",
            font=("TkDefaultFont", 16)
        ).grid(row=0)

        self.recordform = DataRecordForm(self)
        self.recordform.grid(row=1, padx=10)

        self.savebutton = ttk.Button(self, text="Save", command=self.on_save)
        self.savebutton.grid(sticky=tk.E, row=2, padx=10)

        # status bar
        self.status = tk.StringVar()
        self.statusbar = ttk.Label(self, textvariable=self.status)
        self.statusbar.grid(sticky=(tk.W + tk.E), row=3, padx=10)

        self.records_saved = 0 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:26,代码来源:data_entry_app.py

示例15: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Button [as 别名]
def __init__(self, controller):
        super().__init__(controller, bg='white', width=1300, height=800)
        self.controller = controller
        self.node_id_to_node = {}
        self.drag_item = None
        self.start_position = [None]*2
        self.start_pos_main_node = [None]*2
        self.dict_start_position = {}
        self.selected_nodes = set()
        self.filepath = None
        self.proj = 'Mercator'
        self.ratio, self.offset = 1, (0, 0)
        self.bind('<MouseWheel>', self.zoomer)
        self.bind('<Button-4>', lambda e: self.zoomer(e, 1.3))
        self.bind('<Button-5>', lambda e: self.zoomer(e, 0.7))
        self.bind('<ButtonPress-3>', lambda e: self.scan_mark(e.x, e.y))
        self.bind('<B3-Motion>', lambda e: self.scan_dragto(e.x, e.y, gain=1))
        self.bind('<Enter>', self.drag_and_drop, add='+')
        self.bind('<ButtonPress-1>', self.start_point_select_objects, add='+')
        self.bind('<B1-Motion>', self.rectangle_drawing)
        self.bind('<ButtonRelease-1>', self.end_point_select_nodes, add='+')
        self.tag_bind('node', '<Button-1>', self.find_closest_node)
        self.tag_bind('node', '<B1-Motion>', self.node_motion) 
开发者ID:afourmy,项目名称:pyGISS,代码行数:25,代码来源:extended_pyGISS.py


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