【发布时间】:2014-05-01 18:34:56
【问题描述】:
我正在尝试创建一个包含带有滚动条的列表框的弹出窗口。但是,我不明白为什么在 Python 中运行代码时什么都没有显示。一如既往,非常感谢!
from Tkinter import *
def run():
# create the root and the canvas
root = Tk()
canvasW, canvasH = 300, 200
canvas = Canvas(root, width=canvasW, height=canvasH)
canvas.pack()
class Struct: pass
canvas.data = Struct()
init(canvas)
root.mainloop()
def init(canvas):
master = Tk()
# use width x height + x_offset + y_offset (no spaces!)
master.geometry("240x180+130+180")
# create the listbox (height/width in char)
listbox = Listbox(master, width=20, height=6)
listbox.grid(row=0, column=0)
# create a vertical scrollbar to the right of the listbox
yscroll = Scrollbar(command=listbox.yview, orient=VERTICAL)
yscroll.grid(row=0, column=1, sticky='ns')
listbox.configure(yscrollcommand=yscroll.set)
# now load the listbox with data
numbers = ["1", "2", "3"]
for item in numbers:
# insert each new item to the end of the listbox
listbox.insert(END, item)
run()
【问题讨论】:
标签: python listbox tkinter scrollbar