
2021-04-11 Python tkinter 之 Scrollbar 与 Listbox、Entry 等控件联用
发布日期:2021-05-04 07:31:32
浏览次数:17
分类:原创文章
本文共 1250 字,大约阅读时间需要 4 分钟。
Scrollbar 控件通常与 Text 、Canvas和 Listbox等一起使用,水平滚动条还能跟 Entry 搭配。正确运用的关键在于orient=tk.VERTICAL、yscrollcommand=scrollbar.set和command=listbox.yview ,这些是垂直卷动条的;若要使用水平卷动条把这三个关键词换成 orient=tk.HORIZONTAL、xscrollcommand=scrollbar.set 和 command=listbox.xview。
tScroll=tk.Scrollbar(win, orient=tk.VERTICAL)
tList=tk.Listbox(win,selectmode=tk.BROWSE,yscrollcommand=tScroll.set)
tScroll.config(command=tList.yview)
例程源代码:
import pyautogui as pgimport tkinter as tkdef winOpen(W,H): X,Y=pg.size() W,H=480,360 X0=(X-W)//2 Y0=(Y-H)//2 winSize=str(W)+'x'+str(H) winPos=winSize+'+'+str(X0)+'+'+str(Y0) win.geometry(winPos) win.resizable(False,False) win.wm_attributes('-topmost',True) title=u'scrollbar测试' win.title(title) win.update()if __name__=='__main__': win=tk.Tk() winOpen(400,300) dicA={11:'AAA',22:'BBB',33:'CCC',44:'DDD',55:'EEE',66:'FFF',77:'GGG'} tScroll=tk.Scrollbar(win, orient=tk.VERTICAL) tScroll.place(x=260,y=95,height=80) tList=tk.Listbox(win,selectmode=tk.BROWSE,yscrollcommand=tScroll.set) tList.place(x=100,y=95,width=160,height=80) for item,value in dicA.items(): tList.insert(tk.END,str(item)+' '+value) tScroll.config(command=tList.yview) win.mainloop()
运动效果:
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2025年03月21日 05时59分58秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
P1026 统计单词个数&&SSL1017
2019-03-04
SSLOJ1692 USACO 3.2 Magic Squares 魔板&P2730
2019-03-04
SSLOJ1063 统计数字
2019-03-04
P4305 [JLOI2011]不重复数字
2019-03-04
P3957 [NOIP2017 普及组] 跳房子
2019-03-04
P3374 【模板】树状数组 1
2019-03-04
《ybtoj高效进阶》第二部分第二章例题5 子正方形
2019-03-04
P1381 单词背诵
2019-03-04
SSLOJ1230 战略游戏
2019-03-04
P5854 【模板】笛卡尔树
2019-03-04
SpringMVC的基础配置之注解驱动
2019-03-04
在Ubuntu上安装GCC编译器
2019-03-04
Maven(高级)之聚合
2019-03-04
快速构建SpringBoot工程
2019-03-04
SpringBoot配置之配置文件分类
2019-03-04
Vue中使用v-for不能用index作为key值
2019-03-04
position: fixed如何相对父元素定位
2019-03-04
SecureCRT注册机
2019-03-04
供应商解决了mini-LED的生产问题 新款MBP蓄势待发?
2019-03-04
new对象实际是在干嘛,懂了后String相关面试题随便推导
2019-03-04