在python中,如何使用滚动条和按钮选择用户在列表中单击的行? 我试着用按钮的命令来定义函数Get。。。我有线索吗。 这是我目前为止的代码:
from tkinter import *
def get():
userline=leftside.get(line)
print(userline)
def scale():
thescale=Tk()
scroll=Scrollbar(thescale)
scroll.pack(side=RIGHT, fill=Y)
leftside = Listbox(thescale, yscrollcommand = scroll.set)
for line in range(101):
leftside.insert(END, "Scale "+str(line))
leftside.pack(side=LEFT, fill=BOTH)
scroll.config(command=leftside.yview)
selectbutton=Button(thescale, text="Select", command=get)
selectbutton.pack()
thescale.mainloop()
scale()
Listbox小部件作为“活动”索引,与用户上次单击的项相对应。所以
leftside.get('active')
会给你想要的东西。另外,如果将get
方法移出scale
,则需要使leftside
成为全局变量,否则不能在get
内使用它。在相关问题 更多 >
编程相关推荐