PYTHON

 1 from tkinter import *
 2 
 3 root = Tk()
 4 
 5 sb = Scrollbar(root)
 6 sb.pack(side=RIGHT,fill=Y)
 7 
 8 lb = Listbox(root,yscrollcommand=sb.set)#介个命令则是lb的命令 内容滚动,滚动轴也滚动 删掉则内容动滚动轴不跟着动
 9 for i in range(1000):
10     lb.insert(END,i)
11 
12 lb.pack(side=LEFT,fill=BOTH)
13 
14 sb.config(command=lb.yview)#这个意思就是 滚动轴滚动带着lb的内容一起滚 如果不加这句话 光滑动滚动轴,内容是不动的
15 #互通互联 
16 mainloop()
 1 #获取滑块的当前位置Scale
 2 from tkinter import *
 3 
 4 root = Tk()
 5 '''
 6 Scale(root,from_=0,to=24).pack()
 7 Scale(root,from_=0,to=200,orient=HORIZONTAL).pack()
 8 #默认是竖直的 想改成水平方向orient=HORIZONTAL
 9 不重新设变量的话直接在后面跟pack的话就好 重新设置的话得在起一行
10 '''
11 s1 = Scale(root,from_=0,to=24)
12 s1.pack()
13 s2 = Scale(root,from_=0,to=200,orient=HORIZONTAL)
14 s2.pack()
15 
16 def show():
17     print(s1.get())
18     print(s2.get())
19     print(s1.get() ,s2.get())#输出 4 29 (中间无逗号)
20 Button(root,text="获取位置",command=show).pack()
21 
22 
23 
24 mainloop()
25 '''
26 加刻度 tickinterval  加精度resolution 就是只能几个格几个格的走 height就是滚动条的长度 太短的话刻度都挤在一起看不清了
27 s1 = Scale(root,from_=0,to=30,tickinterval=5,resolution=5,height=200)
28 s1.pack()
29 
30 s2 = Scale(root,from_=0,to=200,tickinterval=10,height=600)
31 s2.pack()
32 '''

 光标形状变化

 1 from tkinter import *
 2 import webbrowser
 3 
 4 root = Tk()
 5 
 6 text = Text(root,width=30,height=5)
 7 text.pack()
 8 
 9 text.insert(INSERT,"寻寻觅觅冷冷清清凄凄惨惨戚戚")
10 
11 text.tag_add("tag1","1.3","1.8")
12 text.tag_config("tag1",foreground="blue",underline="true")
13 
14 def show_arrow_cursor(event):
15     text.config(cursor="arrow")
16 def show_xterm_cursor(event):
17     text.config(cursor="xterm")
18 def click(event):
19     webbrowser.open("www.baidu.com")
20 
21 text.tag_bind("tag1","<Enter>",show_arrow_cursor)
22 text.tag_bind("tag1","<Leave>",show_xterm_cursor)
23 text.tag_bind("tag1","<Button-1>",click)
24 
25 
26 mainloop()
27 
28 '''
29 text = Text(root,width=50,height=5)
30 text.pack()
31 
32 text.insert(INSERT,"寻寻觅觅冷冷清清凄凄惨惨戚戚")
33 text.tag_add("tag1","1.2","1.5","1.8")#tag_add:就是添加一个tag 范围从第一行第三列到第一行第五列 +第一行第九个元素 行从1开始列从0开始
34 text.tag_config("tag1",background="yellow",foreground="red")#tag_config用于设置标签的样式
35 #标签设置时如果冲撞,新标签覆盖旧
36 #tag_config也可以新命令一个标签 如果标签之前没有声明的话 tag_raise/tag_lower
37 '''

 

posted @ 2019-06-13 23:08  像走了一光年  阅读(140)  评论(0编辑  收藏  举报