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


Python Listbox.place方法代码示例

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


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

示例1: initUI

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import place [as 别名]
    def initUI(self):
      
        self.parent.title("Listbox") 
        
        self.pack(fill=BOTH, expand=1)

        IP_list = ['IP Address 1', 'IP Address 2', 'IP Address 3', 'IP Address 4', 'IP Address 5', 'IP Address 6', 'IP Address 7', 'IP Address 8', 'IP Address 9', 'IP Address 10', 'IP Address 11', 'IP Address 12', 'IP Address 13', 'IP Address 14', 'IP Address 15', 'IP Address 16']
        IP_numbers = ['150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1']

        lb = Listbox(self)
        for i in IP_list:
            lb.insert(END, i)
            
        lb.bind("<<ListboxSelect>>", self.onSelect)    
            
        lb.place(x=20, y=20)

        self.var = StringVar()
        self.label = Label(self, text=0, textvariable=self.var)        
        self.label.place(x=20, y=270)

        #
        self.columnconfigure(1, weight=1)
        self.columnconfigure(3, pad=7)
        self.rowconfigure(3, weight=1)
        self.rowconfigure(5, pad=7)
        
        #lbl = Label(self, text="Windows")
        lb.grid(sticky=W, pady=40, padx=50)
        
        #lb = Text(self)
        lb.grid(row=1, column=0, columnspan=2, rowspan=4, 
            padx=50, sticky=E+W+S+N)
        
        abtn = Button(self, text="Activate")
        abtn.grid(row=1, column=3)

        cbtn = Button(self, text="Close")
        cbtn.grid(row=2, column=3, pady=4)
        
        hbtn = Button(self, text="Help")
        hbtn.grid(row=5, column=0, padx=5)

        obtn = Button(self, text="OK")
        obtn.grid(row=5, column=3)
开发者ID:dfitz360,项目名称:Drop-py,代码行数:47,代码来源:RossLearning.py

示例2: initUI

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import place [as 别名]
    def initUI(self):
        self.parent.title("Listbox")
        self.pack(fill=BOTH, expand=1)

        acts = ['Scarlett Johansson', 'Rachel Weiss',
            'Natalie Portman', 'Jessica Alba']

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

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

        lb.place(x=20, y=20)

        self.var = StringVar()
        self.label = Label(self, text=0, textvariable=self.var)
        self.label.place(x=20, y=210)
开发者ID:KimBoWoon,项目名称:Python_Practice,代码行数:20,代码来源:TKBook.py

示例3: Main

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import place [as 别名]
class Main(Frame):
    def __init__(self, parent, controller):
        Frame.__init__(self, parent)
        self.controller = controller
        self.db_set = False

        self.configure(relief=GROOVE)
        self.configure(borderwidth="2")

        # Manual link adding
        self.manual_btn = Button(self)
        self.manual_btn.place(relx=0.07, rely=0.81, height=45, width=130)
        self.manual_btn.configure(activebackground="#d9d9d9")
        self.manual_btn.configure(highlightbackground="#d9d9d9")
        self.manual_btn.configure(pady="0")
        self.manual_btn.configure(text="Add manually")
        self.manual_btn.configure(width=130)

        self.file_btn = Button(self)
        self.file_btn.place(relx=0.67, rely=0.81, height=45, width=150)
        self.file_btn.configure(activebackground="#d9d9d9")
        self.file_btn.configure(highlightbackground="#d9d9d9")
        self.file_btn.configure(pady="0")
        self.file_btn.configure(text="Add from file")

        self.label = Label(self)
        self.label.place(relx=0.08, rely=0.0, height=61, width=484)
        self.label.configure(text="Create new playlists and add content to them")
        self.label.configure(width=485)

        self.listbox = Listbox(self)
        self.listbox.place(relx=0.38, rely=0.22, relheight=0.31, relwidth=0.17)
        self.listbox.configure(background="white")
        self.listbox.configure(disabledforeground="#a3a3a3")
        self.listbox.configure(foreground="#000000")
        self.listbox.configure(selectmode=SINGLE)
        self.listbox.configure(width=105)
        for name, value in config.configparser.items('Playlists'):
            if os.path.isdir(value):
                self.listbox.insert('end', name)
            else:
                config.remove_value('Playlists', name)
        self.listbox.bind('<<ListboxSelect>>', self.onselect)

        self.label_name = Label(self)
        self.label_name.place(relx=0.7, rely=0.22, height=31, width=84)
        self.label_name.configure(foreground="#000000")
        self.label_name.configure(text="Name")
        self.label_name.configure(width=85)

        self.entry = Entry(self)
        self.entry.place(relx=0.63, rely=0.31, relheight=0.08, relwidth=0.29)
        self.entry.configure(background="white")
        self.entry.configure(foreground="#000000")
        self.entry.configure(insertbackground="black")
        self.entry.configure(takefocus="0")
        self.entry.configure(width=175)

        self.change_name = Button(self)
        self.change_name.place(relx=0.7, rely=0.42, height=34, width=97)
        self.change_name.configure(activebackground="#d9d9d9")
        self.change_name.configure(highlightbackground="#d9d9d9")
        self.change_name.configure(highlightcolor="black")
        self.change_name.configure(pady="0")
        self.change_name.configure(text="Rename")
        self.change_name.configure(width=100)

        self.new_playlist = Button(self, command=self.new_database)
        self.new_playlist.place(relx=0.08, rely=0.28, height=54, width=107)
        self.new_playlist.configure(activebackground="#d9d9d9")
        self.new_playlist.configure(highlightbackground="#d9d9d9")
        self.new_playlist.configure(highlightcolor="black")
        self.new_playlist.configure(pady="0")
        self.new_playlist.configure(text="Create new playlist")
        self.new_playlist.configure(width=105)

        self.db_name = Entry(self)
        self.db_name.place(relx=0.07, rely=0.44, relheight=0.08, relwidth=0.22)
        self.db_name.configure(fg='grey')
        self.db_name.configure(width=135)
        self.db_name.insert(0, "Input database name here")
        self.db_name.bind('<Button-1>', lambda event: greytext(self.db_name))

    def onselect(self, event):
        w = event.widget
        index = int(w.curselection()[0])
        value = w.get(index)
        set_database(config.configparser.get('Playlists', value))
        if not database.check_integrity():
            messagebox.showwarning('Integrity check failed', 'You might be missing some entries in your list')
        if not self.db_set:
            self.manual_btn.configure(command=lambda: self.controller.show_frame('AddManually'))
            self.file_btn.configure(command=lambda: self.controller.show_frame('ReadFromFile'))
            self.db_set = True

    def new_database(self):
        name = self.db_name.get()
        names = config.configparser.options('Playlists')
        print(name, names)
        if name.strip() == '' or self.db_name.cget('fg') == 'grey':
#.........这里部分代码省略.........
开发者ID:s0hvaperuna,项目名称:Custom-playlist,代码行数:103,代码来源:addlink.py

示例4: AutoCompleteEntry

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import place [as 别名]
class AutoCompleteEntry(Entry): # pylint: disable=too-many-ancestors
    """
    An entry widget with asdf.
    """
    def __init__(self, autocomplete_list, *args, **kwargs):
        self.autocomplete_list = autocomplete_list
        self.list_box_length = kwargs.pop('list_box_length', 8)
        self.matches_function = kwargs.pop('matches_function',
                                           self._default_match)

        # function to initate_string_var_no_textvariable
        self.textvariable = kwargs.get('textvariable', StringVar())
        self.list_box = None
        super().__init__(*args, **kwargs)
        self.config(textvariable=self.textvariable)
        self.focus()

        self.textvariable.trace('w', self._changed)

    @property
    def existing_list_box(self):
        """
        Check if this instance has its' listbox defined/open.
        """
        return self.__dict__.get('list_box', False)

    @staticmethod
    def _default_match(query, list_entry):
        """
        The default match function if none is given during instantiation.
        """
        pattern = re.compile(re.escape(query) + '.*', re.IGNORECASE)
        return re.match(pattern, list_entry)

    def _changed(self, name, index, mode):
        """
        Event handler for changes to entry.
        """
        print("in _changed")
        print(name, index, mode)

        if self.textvariable.get():  # not empty string
            words = self.__comparison()

            if not words:
                return self.__delete_existing_list_box()

            if not self.existing_list_box:
                self.list_box = Listbox(width=self["width"],
                                        height=self.list_box_length)
                # looks hacky
                self.list_box.place(
                    x=self.winfo_x(), y=self.winfo_y() + self.winfo_height())
                self.list_box.delete(0, END)
                for word in words:
                    self.list_box.insert(END, word)
        else:
            self.__delete_existing_list_box()

    def __delete_existing_list_box(self):
        """
        Deletes open listbox.
        """
        if self.existing_list_box:
            self.list_box.destroy()

    # hmmmm
    def __comparison(self):
        """
        Finds words similar to query. TODO
        """
        if len(self.get()) < 3:
            return []
        ans = [w for w in self.autocomplete_list if
               self.matches_function(self.textvariable.get(), w)]
        print(ans)
        return ans[:5]
开发者ID:pathway27,项目名称:revolver,代码行数:79,代码来源:autocomplete_entry.py

示例5: AutocompleteEntry

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import place [as 别名]
class AutocompleteEntry(Entry):

    def __init__(self, *args, **kwargs):
        Entry.__init__(self, width=100, *args, **kwargs)

        self.focus_set()
        self.pack()

        self.var = self["textvariable"]
        if self.var == '':
            self.var = self["textvariable"] = StringVar()

        self.var.trace('w', self.changed)
        self.bind("<Right>", self.selection)
        self.bind("<Up>", self.up)
        self.bind("<Down>", self.down)
        self.bind("<Return>", self.enter)
        self.lb_up = False
        self.lb = None

    def enter(self, event):
        print(event)

    def changed(self, name, index, mode):

        if self.var.get() == '':
            if self.lb:
                self.lb.destroy()
            self.lb_up = False
        else:
            words = self.comparison()
            if words:
                if not self.lb_up:
                    self.lb = Listbox(master=root, width=100)

                    self.lb.bind("<Double-Button-1>", self.selection)
                    self.lb.bind("<Right>", self.selection)
                    self.lb.place(x=self.winfo_x(), y=self.winfo_y()+self.winfo_height())
                    self.lb_up = True

                self.lb.delete(0, END)
                for w in words:
                    self.lb.insert(END,w)
            else:
                if self.lb_up:
                    self.lb.destroy()
                    self.lb_up = False

    def selection(self, _):

        if self.lb_up:
            self.var.set(self.lb.get(ACTIVE))
            self.lb.destroy()
            self.lb_up = False
            self.icursor(END)

    def up(self, _):

        if self.lb_up:
            if self.lb.curselection() == ():
                index = '0'
            else:
                index = self.lb.curselection()[0]
            if index != '0':
                self.lb.selection_clear(first=index)
                index = str(int(index)-1)
                self.lb.selection_set(first=index)
                self.lb.activate(index)

    def down(self, _):

        if self.lb_up:
            if self.lb.curselection() == ():
                index = '0'
            else:
                index = self.lb.curselection()[0]
            if index != END:
                self.lb.selection_clear(first=index)
                index = str(int(index)+1)
                self.lb.selection_set(first=index)
                self.lb.activate(index)

    def comparison(self):
        q = self.var.get()
        q = str(q.decode('utf8'))
        for hit in searcher.search(qp.parse(q), limit=50):
            if hit['author']:
                yield '%s. "%s"' % (hit['author'], hit['title'])
            else:
                yield hit['title']
开发者ID:timvieira,项目名称:skid,代码行数:92,代码来源:tkautocomplete.py


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