在python上滚动Entry小部件

我尝试在python中滚动条目。当我运行程序时,什么都不会发生。请有人帮我吗??这是我的代码:

选择 | 换行 | 行号
  1. self.scrollbar = tk.Scrollbar(self,orient="horizontal")
  2.         self.e3 =tk.Entry(self,xscrollcommand=self.scrollbar.set)
  3.         self.e3.focus()
  4.         self.e3.pack(side="bottom",fill="x")
  5.         #self.e3.grid(row=10, column=7)
  6.         self.scrollbar.pack(fill="x")
  7.         self.scrollbar.config(command=self.e3.xview)
  8.         self.e3.config()
# 回答1

它在Slackware Linux上运行良好。请注意,要滚动,必须有一个比框宽的条目。

选择 | 换行 | 行号
  1. class TestEntry():
  2.     def __init__(self):
  3.             root = tk.Tk()
  4.             self.scrollbar = tk.Scrollbar(root,orient="horizontal")
  5.             txt = tk.StringVar()
  6.             self.e3 =tk.Entry(root,
  7.                      xscrollcommand=self.scrollbar.set,
  8.                      textvariable=txt)
  9.             txt.set("ABC"*10)  ## add some text to scroll
  10.             self.e3.focus()
  11.             self.e3.pack(side="bottom",fill="x")
  12.             self.scrollbar.pack(fill="x")
  13.             self.scrollbar.config(command=self.e3.xview)
  14.             self.e3.config()
  15.  
  16.             root.mainloop()
  17.  
  18. TestEntry() 

标签: python

添加新评论