tkinter Text.yview_scroll(number,what)怎么用

thinker56 2012-10-05 03:11:59
tkinter   Text.yview_scroll(number,what)怎么用呀
?????????????
我不想另外去初始化并设置一个Scrollbar控件
class TextCopyer():
def __init__(self):
import tkinter
#配置窗口top
top=tkinter.Tk()
top.title('抄写窗口')
top.geometry('800x200+270+500')
top.wm_attributes('-topmost',True)
#配置文本框控件txt
self.txt=tkinter.Text(top,
width=114,
height=12,
borderwidth=2,
bg='black',
fg='green'
)
self.txt.yview_scroll(-10,'units')
self.txt.yview()
self.txt.place(x=0,y=0)
top.mainloop()

if __name__ == '__main__':
TextCopyer()

number通过报错知道它得是integer类型

我试了-100-0-100的值,都没有用
滚动条显示不出来
...全文
1017 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel_su 2012-10-07
  • 打赏
  • 举报
回复
看看python文档,有个现成的ScrolledText模块,结合了Text+Scroolbar,试试...
thinker56 2012-10-07
  • 打赏
  • 举报
回复
我还以为这个方法,可以自动为Text控件添加一个滚动条呢,没想到它只是一个上下滚动的方法

这么说Text没有自带的滚动条了,看来还是得自己动手创建一个Scroolbar控件,真麻烦



谢谢楼上的回复。。。
angel_su 2012-10-05
  • 打赏
  • 举报
回复
yview_scroll(-10,'units')这样可以的,只不过你的txt没有文字就着急调用函数,那你能看到啥效果,下面改用两个按钮调用该函数,先贴点蚊子进去后再操作,能正常卷动10行...
from Tkinter import *

def Up10():
txt.yview_scroll(-10, 'units')

def Dn10():
txt.yview_scroll(10, 'units')

root=Tk()
Button(root, text="^^^", command=Up10).pack()
txt = Text(root, width=80, height=12)
txt.pack()
Button(root, text="vvv", command=Dn10).pack()
root.mainloop()


libralibra 2012-10-05
  • 打赏
  • 举报
回复
1. 大小写是Tkinter,T要大写
2. Text没看到yview_scroll方法啊,只有xview和yview,分别有多种方法滚动,一般用yview(MOVETO,offset)这种,下面是文档

xview(), yview().

Returns a tuple containing two values; the first value corresponds to the relative offset of the first visible line (column), and the second corresponds to the relative offset of the line (column) just after the last one visible on the screen. Offset 0.0 is the beginning of the text, 1.0 the end.


xview(MOVETO, offset), yview(MOVETO, offset).

Adjust the text widget so that the given offset is at the left (top) edge of the text. Offset 0.0 is the beginning of the text, 1.0 the end. These methods are used by the Scrollbar bindings when the user drags the scrollbar slider.

The MOVETO constant is not defined in Python 1.5.2 and earlier. For compatibility, use the string "moveto" instead.


xview(SCROLL, step, what), yview(SCROLL, step, what).

Scroll the text widget horizontally (vertically) by the given amount. The what argument can be either UNITS (lines, characters) or PAGES. These methods are used by the Scrollbar bindings when the user clicks at a scrollbar arrow or in the trough.

37,735

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧