Seite 1 von 1

Wie heißt dieses widget?

Verfasst: Dienstag 25. November 2014, 16:03
von HardwareManager
Ich habe eine frage:
Wie macht man das hier:
Bild

Danke!

Re: Wie heißt dieses widget?

Verfasst: Dienstag 25. November 2014, 21:18
von Michael Schneider
So in etwa? :)

Code: Alles auswählen

import Tkinter as tk

itemslist = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii",
             "jjj", "kkk", "LLL", "mmm", "nnn", "ooo", "ppp", "qqq", "rrr",
             "sss", "this is an example of a very long option which you may "
             "or may not wish to choose."*2, "ttt", "uuu", "vvv", "www", "xxx"]

class ScrolledListbox(tk.Frame):
    def __init__(self, *args, **kwds):
        tk.Frame.__init__(self, *args, **kwds)
        self._create_gui(**kwds)
        
    def _create_gui(self, width=30, height=20, **kwds):
        self.listbox = tk.Listbox(self, width=width, height=height, **kwds)
        self.listbox.grid(row=1, column=1, sticky="nsew")
        self.scrollx = tk.Scrollbar(self, orient="horizontal", command=self.listbox.xview)
        self.scrollx.grid(row=2, column=1, sticky="ew")
        self.scrolly = tk.Scrollbar(self, orient="vertical", command=self.listbox.yview)
        self.scrolly.grid(row=1, column=2, sticky="ns")
        self.listbox.config(xscrollcommand=self.scrollx.set, yscrollcommand=self.scrolly.set)
        
if __name__ == "__main__":
    root = tk.Tk()
    frame = ScrolledListbox(root, width=80, height=20)
    frame.grid()
    for item in itemslist:
        frame.listbox.insert("end", item)
    root.mainloop()

Re: Wie heißt dieses widget?

Verfasst: Mittwoch 26. November 2014, 06:56
von Ene Uran
Tix had die ScrolledListbox schon mal eingebaut:

Code: Alles auswählen

''' Tix_ScrolledListBox2.py
Tkinter extension module tix comes with Python27 and Python31+
explore the tix.ScrolledListBox
vertical or horizontal scroll bars appear as needed (automatic)
for more info check ...
http://docs.python.org/library/tix.html  
http://doc.astro-wise.org/Tix.html
actually Tix imports Tkinter so you can call it all tix
'''

try:
    #import Tkinter as tk
    import Tix as tix  # Python27
except ImportError:
    #import tkinter as tk
    import tkinter.tix as tix  # Python31 and higher

app = tix.Tk()
app.title('tix.ScrolledListBox')

scr_list = tix.ScrolledListBox(app, scrollbar='auto')
scr_list.pack(fill='both', expand=1)

s = 'line'
for ix, line in enumerate(range(20)):
    line_text = s + str(ix+1)
    scr_list.listbox.insert('end', line_text)
s = 'a very long line to demo the horizontal automatic scrollbar'
scr_list.listbox.insert('end', s)

app.mainloop()

Re: Wie heißt dieses widget?

Verfasst: Mittwoch 26. November 2014, 07:49
von Michael Schneider
Stimmt. Aber das hatte ich als nicht-Standardbib damals nicht eingebaut und kam daher noch nicht dazu, mich damit zu beschäftigen. Da ist es gut, dass hier Experten aus allen Bereichen herumlaufen, die das aus dem FF sagen können. :D

Re: Wie heißt dieses widget?

Verfasst: Dienstag 2. Dezember 2014, 19:42
von HardwareManager
Ja Danke