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


Python Button.pack方法代码示例

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


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

示例1: initUI

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
    def initUI(self):
        self.parent.title('PyZilla')
        self.padding = 5

        self.pack(fill=BOTH, expand=1)

        # Create a menubar
        mnuMenu = Menu(self.parent)
        self.parent.config(menu=mnuMenu)

        # Create menubar
        mnuFileMenu = Menu(mnuMenu)

        # Add File menu items
        mnuFileMenu.add_command(label='Open', command=self.onBtnOpenFile)
        mnuFileMenu.add_command(label='Exit', command=self.quit)

        # Add File menu items to File menu
        mnuMenu.add_cascade(label='File', menu=mnuFileMenu)

        # Create frame for all the widgets
        frame = Frame(self)
        frame.pack(anchor=N, fill=BOTH)

        # Create file open dialog
        btnOpenFile = Button(frame, text="Load file", command=self.onBtnOpenFile)
        btnOpenFile.pack(side=RIGHT, pady=self.padding)

        # Create filename label
        self.lblFilename = Label(frame, text='No filename chosen...')
        self.lblFilename.pack(side=LEFT, pady=self.padding, padx=self.padding)

        # Create the text widget for the results
        self.txtResults = Text(self)
        self.txtResults.pack(fill=BOTH, expand=1, pady=self.padding, padx=self.padding)
开发者ID:claudemuller,项目名称:pyzilla,代码行数:37,代码来源:pyzilla.py

示例2: Example

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
class Example(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)

        self.toolbar = Frame(self, bg="#eee")
        self.toolbar.pack(side="top", fill="x")

        self.bold = Button(self.toolbar, text="Bold", command=self.make_bold)
        self.bold.pack(side="left")

        self.clear = Button(self.toolbar, text="Clear", command=self.clear)
        self.clear.pack(side="left")

        # Creates a bold font.
        self.bold_font = Font(family="Helvetica", size=14, weight="bold")

        self.text = Text(self)
        self.text.insert("end", "Select part of text and then click 'Bold'...")
        self.text.focus()
        self.text.pack(fill="both", expand=True)

        # Configures a tag called BOLD.
        self.text.tag_configure("BOLD", font=self.bold_font)

    def make_bold(self):
        # tk.TclError exception is raised if not text is selected.
        try:
            self.text.tag_add("BOLD", "sel.first", "sel.last")
        except TclError:
            pass

    def clear(self):
        self.text.tag_remove("BOLD", "1.0", 'end')
开发者ID:dossan,项目名称:tkinter,代码行数:35,代码来源:style_parts_of_text.py

示例3: __init__

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
class FileChooser:
    def __init__(self):
        self.filechooser = Tk()
        self.filechooser.geometry('500x500+0+0')
        self.button  = Button(self.filechooser,text="Add Directory",command=self.addDir)
        self.listview = Listbox(self.filechooser)
        self.closebutton = Button(self.filechooser,text="Scan",command=self.Done)
        self.listview.pack(fill="both")
        self.button.pack(fill='x')
        helptext = """Select directories by pressing the "Add Directory" Button, then press Scan.
                        \n When the file tree appears, red text means the file or folder is a duplicate.
                        \n purple means the folder contains duplicates but itself is not a duplicate.
                        \n Double Click on red text entries to view matches"""
        self.instructions = Label(self.filechooser, text=helptext)
        self.instructions.pack(fill='both')
        self.closebutton.pack()


        self.filechooser.mainloop()
    def Done(self):
        self.filechooser.destroy()
    def addDir(self):
        dir = askdirectory()
        if os.path.isdir(dir):
            dirlist.append(dir)
            self.listview.insert('end',str(dir))
开发者ID:bretttjohnson1,项目名称:Duplicate_Discoverer,代码行数:28,代码来源:main.py

示例4: __init__

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
class _Testdialog:
    """Only used to test dialog from CLI"""
    def __init__(self, master):
        """Initialize CLI test GUI"""
        frame = Frame(master, width=300, height=300)
        self.master = master
        self.x, self.y, self.w, self.h = -1,-1,-1,-1

        self.Button_1 = Button(frame, text="My Popup", relief="raised", width="15")
        self.Button_1.pack()
        self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click)

        statframe = Frame(frame)
        master.statusMessage = StringVar()
        master.statusMessage.set('Welcome')
        self.statusbar = Label(statframe, textvariable=master.statusMessage,
                               bd=1, relief=SUNKEN, anchor=W)
        self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
        statframe.pack(anchor=SW, fill=X, side=BOTTOM)
        self.dx = 30
        self.dy = 30

        frame.pack()

        self.dialog = None

    # pylint: disable=W0613
    def Button_1_Click(self, event): #click method for component ID=1
        """Launch Select_Py_Version for CLI testing."""
        self.dialog = SatelliteWindow(self, self.master, "Test Dialog", dx=self.dx, dy=self.dy)
        self.dx += 30
        self.dy += 30
开发者ID:sonofeft,项目名称:Tk_Nosy,代码行数:34,代码来源:tk_nosy_popup.py

示例5: Demo

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
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()
开发者ID:jbpeters,项目名称:Time-keeper,代码行数:35,代码来源:tkmin.py

示例6: __init__

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
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)
开发者ID:Dark5ide,项目名称:mycroft-core,代码行数:37,代码来源:message_tester.py

示例7: __init__

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
class MyFirstGUI:
    LABEL_TEXT = [
        "This is our first GUI!",
        "Actually, this is our second GUI.",
        "We made it more interesting...",
        "...by making this label interactive.",
        "Go on, click on it again.",
    ]
    def __init__(self, master):
        self.master = master
        master.title("A simple GUI")

        self.label_index = 0
        self.label_text = StringVar()
        self.label_text.set(self.LABEL_TEXT[self.label_index])
        self.label = Label(master, textvariable=self.label_text)
        self.label.bind("<Button-1>", self.cycle_label_text)
        self.label.pack()

        self.greet_button = Button(master, text="Greet", command=self.greet)
        self.greet_button.pack()

        self.close_button = Button(master, text="Close", command=master.quit)
        self.close_button.pack()

    def greet(self):
        print("Greetings!")

    def cycle_label_text(self, event):
        self.label_index += 1
        self.label_index %= len(self.LABEL_TEXT) # wrap around
        self.label_text.set(self.LABEL_TEXT[self.label_index])
开发者ID:gshkr123,项目名称:Python_Task,代码行数:34,代码来源:GUI-Lables.py

示例8: ua_win_tk

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
def ua_win_tk(url, pipe = None):
    from tkinter import Tk, Frame, Label, Entry, StringVar, BOTH, Button, RIGHT
    import sys
    sys.stdout.flush()
    instructions = "Visit the following URL to authorize the application:"
    response = {"x": False}
    root = Tk()
    root.title("oAuth2 Authorization Required")
    webbox = Frame(root)
    instructions = Label(webbox, text = instructions)
    instructions.pack(padx = 5, pady = 5)
    urlstr = StringVar(value = url)
    urlbox = Entry(webbox, textvariable = urlstr, state = "readonly")
    urlbox.pack(padx = 5, pady = 5)
    def open_browser():
        from subprocess import Popen
        p = Popen(["sensible-browser", url])
    browserbutton = Button(webbox, text = "Open in web browser", command = open_browser)
    browserbutton.pack(padx = 5, pady = 5)
    webbox.pack(fill = BOTH, expand = 1)
    if pipe:
        def poll():
            if pipe.poll():
                root.destroy()
                #Mutability ftw... wat
                response["x"] = True
            else:
                root.after(300, poll)
        root.after(300, poll)
    cancelbutton = Button(root, text = "Cancel", command = root.destroy)
    cancelbutton.pack(side = RIGHT, padx = 5, pady = 5)
    root.mainloop()
    return response["x"]
开发者ID:pyokagan,项目名称:pyoauth2client,代码行数:35,代码来源:ui.py

示例9: initUI

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
    def initUI(self):
      
        self.lineCounter = 0
      
        # create a custom font
        self.customFontHeader = font.Font(family="Calibri", slant = "italic") #family="Helvetica", weight="bold", slant="italic")
        self.customFontMessage = font.Font(family="Calibri")
        
        self.parent.title("Python Chat") 
        
        frame = Frame(self.parent)
        frame.pack(fill=BOTH, expand=1, side=LEFT)
        
        self.box = ScrolledText(frame, wrap=WORD, relief = GROOVE, width=30, height=18, font=self.customFontMessage)
        self.box.insert(END, 'Welcome to Python Chat!')
        self.box.config(state=DISABLED)
        self.box.pack(expand="yes", fill=BOTH, side=TOP)
        
        self.textarea = Text(frame, width=30, height=5)
        #self.textarea.insert(END, "")
        self.textarea.bind("<KeyRelease-Return>", self.gettext) #Se metto on press, rimane una newline in piu
        self.textarea.pack(expand="yes", fill=BOTH, side=TOP)

        
        okButton = Button(frame, text="Panic Button", activebackground="red", command=self.sendFile) 
        okButton.pack(expand="no", fill=BOTH, side=TOP)
        
        self.usersFrame = Frame(self.parent)
        self.usersFrame.pack(fill=BOTH, expand=1, side=RIGHT)
        
        self.userListbox = Listbox(self.usersFrame, width=3)
        self.userListbox.pack(fill=BOTH, expand=1)
            
        self.updateUsersFrame()
开发者ID:skimdz86,项目名称:Utilities,代码行数:36,代码来源:BlinkingChatGUIClient.py

示例10: ProgramWidget

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
class ProgramWidget(Frame):

    def __init__(self, parent, client):
        super(ProgramWidget, self).__init__(parent)
        self.client = client
        self.client.onProgramChange = self.programChanged

        self.programLabel = Label(self, text = 'Program:')
        self.programLabel.grid(row = 0, column = 0)
        self.programEntry = Entry(self, text = 'Program name',
                                  state = 'readonly')
        self.programEntry.grid(row = 0, column = 1)
        self.buttonPanel = Frame(self)
        self.buttonPanel.grid(row = 1, column = 0, columnspan = 2, sticky = W)
        self.newButton = Button(self.buttonPanel, text='New',
                                command = self.newProgram)
        self.newButton.pack(side = LEFT)

    def programChanged(self):
        self.__setProgramText(str(self.client.state))

    def __setProgramText(self, text):
        self.programEntry.configure(state = NORMAL)
        self.programEntry.delete(0)
        self.programEntry.insert(0, text)
        self.programEntry.configure(state = 'readonly')

    def newProgram(self):
        self.client.makeNewProgram()
开发者ID:mindhog,项目名称:mawb,代码行数:31,代码来源:tkui.py

示例11: Example

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
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)
开发者ID:floydxiu,项目名称:Crypto_learning,代码行数:31,代码来源:letter_analysis.py

示例12: pack_windows

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
def pack_windows(root):
    main_paned_window = PanedWindow(root)
    main_paned_window.pack(fill=BOTH, expand=True)

    tone_paned_window=PanedWindow(relief=tk.GROOVE,bd=3,orient=tk.VERTICAL)
    main_paned_window.add(tone_paned_window)
    
    sub_tone_paned_window=PanedWindow(tone_paned_window)
    tone_paned_window.add(sub_tone_paned_window)
    
    plot_window=PanedWindow()
    main_paned_window.add(plot_window)
    plot_window=ImageViewer(plot_window)
    plot_window.canvas.get_tk_widget().pack(fill=tk.BOTH,expand=True)

    tone_window=ToneCurveViewer(sub_tone_paned_window,plot_window)
    tone_window.canvas.get_tk_widget().pack(fill=tk.BOTH,expand=True)
    space_frame=Frame()
    tone_paned_window.add(space_frame)
    
    button=Button(space_frame,text="something")
    button.pack()

    def quit_app():
        root.quit()
        root.destroy()

    quitbutton=Button(space_frame,text="exit",command=quit_app)
    quitbutton.pack()
开发者ID:terasakisatoshi,项目名称:PythonCode,代码行数:31,代码来源:plot_win.py

示例13: show_captcha

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
    def show_captcha(self,img_file):
        dialogRoot = Tk()
        dialogRoot.title("Input text.")
    
        img = PhotoImage(file=img_file)
    
        frame = Frame(dialogRoot)
    
        imal = Label(frame, image=img)
        imal.pack()
    
        label = Label(frame)
        label['text'] = "Your Input:"
        label.pack(side=LEFT)
    
        inputEntry = Entry(frame)
        inputEntry["width"] = 50
        inputEntry.pack(side=LEFT)
    
        def getInputText():
            '''callback of button'''
            # global inputEntry, dialogRoot
            if inputEntry.get().strip() == "":
                print("Please enter a message.")
            else:
                self.captcha_ans = inputEntry.get().strip()
                dialogRoot.destroy()

    
        button = Button(frame, text="Submit", command=getInputText)
        button.pack(side=LEFT)
    
        frame.pack()
        dialogRoot.mainloop()
开发者ID:fscnick,项目名称:RapidgatorDownloader,代码行数:36,代码来源:OtherUtility.py

示例14: MainWindow

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
class MainWindow(Frame):
    def createWidgets(self):
        self.nameLabel = Label(self, text="What's your name:")
        self.nameLabel.pack(side='top')
        
        self.nameInput = EntryTextHolder(self)
        self.nameInput.pack(side='top', fill='x', expand=True)
        
        self.helloLabel = LabelTextHolder(self)
        self.helloLabel.pack(side='top')
        
        self.sayHelloButton = Button(self, text="Say Hello")
        self.sayHelloButton.pack(side='right')
        self.sayHelloButton['command'] = self.model.say_hello
        
        self.randomNameButton = Button(self, text="Random Name")
        self.randomNameButton.pack(side='right')
        self.randomNameButton['command'] = self.model.select_random_name
    
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.model = MainWindowModel()        
        self.pack()
        self.createWidgets()
        self.model.set_children(self.nameInput.model, self.helloLabel.model)
开发者ID:daleathan,项目名称:guiskel,代码行数:27,代码来源:mainwindow.py

示例15: main

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import pack [as 别名]
def main():
    root = Tk()
    app = Example(root)

    b = Button(root, text="OK", command=showMsg)

    b.pack()
    root.mainloop()
开发者ID:tiborv,项目名称:tdt4140-swag,代码行数:10,代码来源:tkintertest.py


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