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


Python Label.pack方法代码示例

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


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

示例1: Example

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label 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("Listbox")
        self.pack(fill=BOTH, expand=1)

        acts = ["Scarlett Johansson", "Rachel Weiss", "Natalie Portman", "Jessica Alba", "Angelina jolie", "Emma Stone", "Sandra Bullock", "Julia Roberts",
        "Jennifer Lawrence", "Mila Kunis", "Jennifer Aniston", "Charlize Theron", "Cameron Diaz", "Nicole Kidman", "Meryl Streep", "Reese Witherspoon"]

        lb = Listbox(self, selectmode="multiple")
        for i in acts:
            lb.insert(END, i)

        lb.bind("<<ListboxSelect>>", self.onSelect)

        lb.pack(pady=15)

        self.var = StringVar()
        self.label = Label(self, text=0, textvariable=self.var)
        self.label.pack()

    def onSelect(self, val):
        sender = val.widget
        idx = sender.curselection()
        value = sender.get(idx)
        self.var.set(value)
开发者ID:Exodus111,项目名称:Projects,代码行数:32,代码来源:listbox.py

示例2: Form

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

        self.parent.title("Example Form")
        self.pack(fill=BOTH, expand=True)

        f = Frame(self)
        f.pack(fill=X)

        l = Label(f, text='First Name', width=10)
        l.pack(side=LEFT, padx=5, pady=5)
       
        self.firstName = Entry(f)
        self.firstName.pack(fill=X, padx=5, expand=True)
        
        f = Frame(self)
        f.pack(fill=X)
        
        l = Label(f, text='Last Name', width=10)
        l.pack(side=LEFT, padx=5, pady=5)

        self.lastName = Entry(f)
        self.lastName.pack(fill=X, padx=5, expand=True)
        
        f = Frame(self)
        f.pack(fill=X)

        l = Label(f, text='Full Name', width=10)
        l.pack(side=LEFT, padx=5, pady=5)

        self.fullName = Label(f, text='ALEX POOPKIN', width=10)
        self.fullName.pack(fill=X, padx=5, expand=True)

        f = Frame(self)
        f.pack(fill=X)

        l = Label(f, text='', width=10)
        l.pack(side=LEFT, padx=5, pady=0)

        self.errorMessage = Label(f, text='Invalid character int the name!', foreground='red', width=30)
        self.errorMessage.pack(fill=X, padx=5, expand=True)

        f = Frame(self)
        f.pack(fill=X)

        b = Button(f, text='Close', command=lambda : self.parent.quit())
        b.pack(side=RIGHT, padx=5, pady=10)
        b['default'] = ACTIVE
        b.focus_set()

        self.clearButton = Button(f, text='Clear')
        self.clearButton.pack(side=RIGHT, padx=5, pady=10)
        self.clearButton['state'] = DISABLED

        self.sendButton = Button(f, text='Send')
        self.sendButton.pack(side=RIGHT, padx=5, pady=10)
开发者ID:alex-kooper,项目名称:knockouttk,代码行数:62,代码来源:form.py

示例3: StatusBar

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
class StatusBar(TagReaderListener):
    def __init__(self, master):
        super().__init__()
        self.label = Label(master, text='', anchor=W)
        self.label.pack()
        self.index = 0
        self.expected_count = 0

    def start_task(self, text):
        self.label['text'] = text + "..."

    def task_complete(self):
        self.label['text'] += 'Done'

    def read_complete(self, elapsed_time):
        self.set("{} files read in {} milliseconds".format(self.expected_count, round(elapsed_time, 2)))

    def read_start(self, count):
        self.expected_count = count
        self.index = 0
        self.set("Reading tags in {} files".format(self.expected_count))

    def file_read(self, file):
        self.index += 1
        percent = round(100 * self.index / self.expected_count, 2)
        self.set("Reading tags in {} files: {}%".format(self.expected_count, percent))

    def counting_files(self):
        self.set("Counting files...")

    def set(self, text: str):
        self.label['text'] = text
开发者ID:realmassy,项目名称:MusicLibrary,代码行数:34,代码来源:ui.py

示例4: DateWidget

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
 class DateWidget(Frame):
     """Gets a date from the user."""
     def __init__(self, master):
         """Make boxes, register callbacks etc."""
         Frame.__init__(self, master)
         self.label = Label(self, text="När är du född?")
         self.label.pack()
         self.entry_text = StringVar()
         self.entry_text.trace("w", lambda *args: self.onEntryChanged())
         self.entry = Entry(self, width=date_entry_width,
              textvariable=self.entry_text)
         self.entry.insert(0, "ÅÅÅÅ-MM-DD")
         self.entry.pack(pady=small_pad)
         self.button = Button(self, text="Uppdatera",
              command=lambda: self.onDateChanged())
         self.button.pack()
         self.entry.focus_set()
         self.entry.select_range(0, END)
         self.entry.bind("<Return>", lambda x: self.onDateChanged())
     def setListener(self, pred_view):
         """Select whom to notify when a new date is entered."""
         self.pred_view = pred_view
     def onDateChanged(self):
         """Notifies the PredictionWidget that the date has been changed."""
         try:
             date = datetime.datetime.strptime(self.entry.get(),
                  "%Y-%m-%d").date()
             self.pred_view.update(date)
         except ValueError:
             self.entry.configure(foreground="red")
     def onEntryChanged(self):
         """Reset the text color."""
         self.entry.configure(foreground="")
开发者ID:JoelSjogren,项目名称:horoskop,代码行数:35,代码来源:main.py

示例5: __init__

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
    def __init__(self, url):
        self.url = url

        self.root = Tk()
        self.root.title("验证码")

        while True:
            try:
                image_bytes = urlopen(self.url).read()
                break
            except socket.timeout:
                print('获取验证码超时:%s\r\n重新获取.' % (self.url))
                continue
            except urllib.error.URLError as e:
                if isinstance(e.reason, socket.timeout):
                    print('获取验证码超时:%s\r\n重新获取.' % (self.url))
                    continue
        # internal data file
        data_stream = io.BytesIO(image_bytes)
        # open as a PIL image object
        self.pil_image = Image.open(data_stream)
        # convert PIL image object to Tkinter PhotoImage object
        self.tk_image = ImageTk.PhotoImage(self.pil_image)
        self.label = Label(self.root, image=self.tk_image, background='brown')
        self.label.pack(padx=5, pady=5)
        self.button = Button(self.root, text="刷新验证码", command=self.refreshImg)
        self.button.pack(padx=5, pady=5)

        randCodeLable = Label(self.root, text="验证码:")
        randCodeLable.pack(padx=5, pady=5)
        self.randCode = Entry(self.root)
        self.randCode.pack(padx=5, pady=5)

        self.loginButton = Button(self.root, text="登录", default=tkinter.ACTIVE)
        self.loginButton.pack(padx=5, pady=5)
开发者ID:stonezyl,项目名称:urbtix,代码行数:37,代码来源:LoginUI.py

示例6: insert_entry_field

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
 def insert_entry_field(self, txt):
     frame = Frame(self.frame)
     frame.pack(fill="x")
     label = Label(frame, text=txt, width=6)
     label.pack(side="left", anchor="n", padx=5, pady=5)
     entry = Entry(frame)
     entry.pack(fill="x", padx=5, pady=5, expand=True)
     self.entries["Entry"][txt] = entry
开发者ID:Exodus111,项目名称:Projects,代码行数:10,代码来源:main.py

示例7: Main

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
class Main(Frame):
    """Main class for our browser.
        Note that we inherit from Frame, making this a Frame object.
    """
    def __init__(self, master):
        Frame.__init__(self, master)
        self.master = master
        self.master.title("Browser")
        self.header = {"User-Agent":"Tkinter Browser 0.1"}

        # Here we make our widgets.
        self.top_frame = Frame(self)
        self.url_frame = Frame(self.top_frame)
        self.url_label = Label(self.url_frame, text="Url: ", anchor="n")
        self.url_entry = Entry(self.url_frame, width=80)
        self.url_button = Button(self.url_frame, text="Go", command=self.go_button)
        self.bottom_frame = Frame(self)
        self.text_field = Text(self.bottom_frame)

        #Here we pack our widgets.
        self.top_frame.pack(side="top", padx=15, pady=15)
        self.url_frame.pack(anchor="center")
        self.bottom_frame.pack(side="bottom", fill="both", expand=True)
        self.text_field.pack(side="bottom", fill="both", expand=True)
        self.url_label.pack(side="left")
        self.url_entry.pack(side="left", fill="x", expand=True)
        self.url_button.pack(side="left", padx=5)
        self.text_field.config(state="disabled", padx=5, pady=5)

    def go_button(self):
        url = self.url_entry.get()
        if url:
            if "http://" not in url:
                url = "http://"+url
            page_text = self.get_page(url)
            self.text_field.config(state="normal")
            self.text_field.delete(1.0, "end")
            self.text_field.insert("end", page_text)
            self.text_field.config(state="disable")

    def get_page(self, url):
        s = requests.Session()
        resp = s.get(url, headers=self.header)
        data = resp.text
        soup = bs(data, "html.parser")
        page_text = soup.find_all(text=True)
        page_text = filter(self.visible, page_text)
        return "".join([str(i)+'\n' for i in page_text])


    def visible(self, e):
        if e.parent.name in ('style', 'script', '[document]', 'head', 'title'):
            return False
        elif re.match('<!--.*-->', str(e.encode('utf-8'))):
            return False
        return True
开发者ID:Exodus111,项目名称:Projects,代码行数:58,代码来源:browser.py

示例8: insert_text_field

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
 def insert_text_field(self, txt, default=None):
     frame = Frame(self.frame)
     frame.pack(fill="x")
     label = Label(frame, text=txt, width=6)
     label.pack(side="left", anchor="n", padx=5, pady=5)
     entry = Text(frame)
     entry.pack(fill="both", pady=5, padx=5, expand=True)
     if default:
         entry.insert("end", default)
     self.entries["Text"][txt] = entry
开发者ID:Exodus111,项目名称:Projects,代码行数:12,代码来源:load.py

示例9: create_widgets

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
    def create_widgets(self):
        super().create_widgets()
        frame = self.frame
        pathlabel = Label(frame, anchor="w", justify="left", text="Help File Path: Enter URL or browse for file")
        self.pathvar = StringVar(self, self.filepath)
        self.path = Entry(frame, textvariable=self.pathvar, width=40)
        browse = Button(frame, text="Browse", width=8, command=self.browse_file)

        pathlabel.pack(anchor="w", padx=5, pady=3)
        self.path.pack(anchor="w", padx=5, pady=3)
        browse.pack(pady=3)
开发者ID:abalkin,项目名称:cpython,代码行数:13,代码来源:query.py

示例10: insert_entry_field

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
 def insert_entry_field(self, txt, default=None, focus=False):
     frame = Frame(self.frame)
     frame.pack(fill="x")
     label = Label(frame, text=txt, width=6)
     label.pack(side="left", anchor="n", padx=5, pady=5)
     entry = Entry(frame)
     entry.pack(fill="x", padx=5, pady=5, expand=True)
     if default:
         entry.insert("end", default)
     if focus:
         entry.focus_force()
     self.entries["Entry"][txt] = entry
开发者ID:Exodus111,项目名称:Projects,代码行数:14,代码来源:load.py

示例11: initUI

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
    def initUI(self, mainFrame):
        """initialize the User Interface"""
        
        # styles
        style = Style()
        style.configure("GRN.TLabel", background="#ACF059")
        style.configure("GRN.TFrame", background="#ACF059")
        style.configure("BLK.TFrame", background="#595959")
        
        
        # create top frame
        topFrame = Frame(mainFrame, style="GRN.TFrame", padding=8)
        topFrame.pack(fill=BOTH, side=TOP)
        
        # create black border
        borderFrame = Frame(mainFrame, style="BLK.TFrame")
        borderFrame.pack(fill=BOTH, side=TOP)
        
        # create add player frame
        addPlayerFrame = Frame(mainFrame, padding=8)
        addPlayerFrame.pack(side=TOP)
        
        # create text field for add button
        self.nameFieldVar = StringVar()
        self.playerNameEntry = Entry(addPlayerFrame, textvariable = self.nameFieldVar)
        self.playerNameEntry.pack(side=LEFT)
        # create add player button
        addButton = Button(addPlayerFrame, text="Add player")
        addButton.pack(side=LEFT)
        
        # create choose game list
        self.currentGame = StringVar()
        self.currentGame.set(self.gameList[0])
        gameDropDown = OptionMenu(mainFrame, self.currentGame, self.gameList[0], *self.gameList)
        gameDropDown.pack(side=TOP)

        # create start game button
        startGameButton = Button(mainFrame, text="Start")
        
        startGameButton.bind("<Button-1>", self.startGame)
        startGameButton.pack(side=TOP)
        
        # create label and set text
        self.playerString = StringVar()
        self.playerString.set(self.buildPlayerHeaderString())
        headerLabel = Label(topFrame, textvariable=self.playerString, style="GRN.TLabel")
        headerLabel.pack(side=TOP)     
        addButton.bind("<Button-1>", self.onAddPlayerClick)
        self.playerNameEntry.bind("<Key>", self.onAddPlayerEnter)
        
        #set focus
        self.playerNameEntry.focus()
开发者ID:fi-ka,项目名称:DartScore,代码行数:54,代码来源:ui.py

示例12: __init__

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
 def __init__(self, master, **kwargs):
     super(Merge, self).__init__(master, **kwargs)
     warning = Label(self, font=('a', 7), wraplength=300, justify='center', text=_('Warning: This tool should only be used to merge GEDCOM files from this software. If you use other GEDCOM files, the result is not guaranteed.'))
     self.files_to_merge = FilesToMerge(self)
     self.btn_add_file = Button(self, text=_('Add files'), command=self.add_files)
     buttons = Frame(self, borderwidth=20)
     self.btn_quit = Button(buttons, text=_('Quit'), command=self.quit)
     self.btn_save = Button(buttons, text=_('Merge'), command=self.save)
     warning.pack()
     self.files_to_merge.pack()
     self.btn_add_file.pack()
     self.btn_quit.pack(side='left', padx=(0, 40))
     self.btn_save.pack(side='right', padx=(40, 0))
     buttons.pack(side='bottom')
开发者ID:daleathan,项目名称:getmyancestors,代码行数:16,代码来源:fstogedcom.py

示例13: create_widgets

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
    def create_widgets(self):  # Call from override, if any.
        frame = Frame(self, borderwidth=2, relief="sunken")
        label = Label(frame, anchor="w", justify="left", text=self.message)
        self.entry = Entry(frame, width=30)  # Bind name for entry_ok.
        self.entry.focus_set()

        buttons = Frame(self)  # Bind buttons for invoke in unittest.
        self.button_ok = Button(buttons, text="Ok", width=8, command=self.ok)
        self.button_cancel = Button(buttons, text="Cancel", width=8, command=self.cancel)

        frame.pack(side="top", expand=TRUE, fill="both")
        label.pack(padx=5, pady=5)
        self.entry.pack(padx=5, pady=5)
        buttons.pack(side="bottom")
        self.button_ok.pack(side="left", padx=5)
        self.button_cancel.pack(side="right", padx=5)
开发者ID:xulukai,项目名称:cpython,代码行数:18,代码来源:query.py

示例14: get_info

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
 def get_info(self):
     x, y = (self.size[0]/2, self.size[1]/2)
     for i in self.info:
         label_frame= LabelFrame(self, text="name")
         label_frame.pack(fill="y")
         for entry in self.info[i]["Entry"]:
             frame = Frame(label_frame)
             frame.pack(fill="x")
             label = Label(label_frame, text=self.info[i]["Entry"][entry], width=6)
             label.pack(side="left", anchor="n", padx=5, pady=5)
         for text in self.info[i]["Text"]:
             frame = Frame(label_frame)
             frame.pack(fill="x")
             label = Label(label_frame, text=self.info[i]["Text"][text], width=6)
             label.pack(side="left", anchor="n", padx=5, pady=5)
     window = self.canvas.create_window(x, y, window=label_frame, tag="test")
开发者ID:Exodus111,项目名称:Projects,代码行数:18,代码来源:main.py

示例15: initUI

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import pack [as 别名]
    def initUI(self):
        # Initialize and name Window
        self.parent.title("Poly Pocket")
        self.style = Style()
        self.style.theme_use("default")
        self.pack(fill=BOTH, expand=1)

        def new_baseline():

            return
        def old_baseline():
            return
        def test(baseline):
            return
        def spark_connect():
            return
        def leap_connect():
            return
        def quit():
            self.parent.destroy()
            return

        welcome = "Welcome to Poly Pocket!"
        welcome_label = Label(self, text=welcome, font=("Helvetica", 24))
        welcome_label.place(x=5, y=5)
        welcome_label.pack()
        
        baseline_button = Button(self, text="New Baseline",
                command=new_baseline())
        recover_baseline_button = Button(self, text="Recover Baseline",
                command=old_baseline())
        test_button = Button(self, text="Conduct Test",
                command=test(self.baseline))
        connect_leap_button = Button(self, text="Establish Leap Connection",
                command=leap_connect)
        connect_spark_button = Button(self, text="Establish Spark Connection",
                command=spark_connect)
        exit_button = Button(self, text="Quit",
                command=quit)
        
        baseline_button.place(relx=0.5, rely=0.3, anchor=CENTER)
        recover_baseline_button.place(relx=0.5, rely=0.4, anchor=CENTER)
        test_button.place(relx=0.5, rely=0.5, anchor=CENTER)
        connect_leap_button.place(relx=0.5, rely=0.6, anchor=CENTER)
        connect_spark_button.place(relx=0.5, rely=0.7, anchor=CENTER)
        exit_button.place(relx=0.5, rely = 0.8, anchor=CENTER)
开发者ID:AwesomeShayne,项目名称:polypocket,代码行数:48,代码来源:main.py


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