Wie heißt dieses widget?
Verfasst: Dienstag 25. November 2014, 16:03
Ich habe eine frage:
Wie macht man das hier:
Danke!
Wie macht man das hier:
Danke!
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
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()
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()