python触屏模块_触摸屏滚动Tkinter Python
以Saad的代码为基础,我使用yview_moveto对其进行了修改,使其能在每个s.O.(win、linux、mac)上运行,并且我在这里解释了一些修改。在
编辑:我编辑了代码以显示完整的类。在class VerticalScrolledFrame(Frame):
"""A pure Tkinter scrollable frame that actually works!
* Use the 'interior' attribute to place widgets inside the scrollable frame
* Construct and pack/place/grid normally
* This frame only allows vertical scrolling
"""
def __init__(self, parent, bg,*args, **kw):
Frame.__init__(self, parent, *args, **kw)
# create a canvas object and a vertical scrollbar for scrolling it
canvas = Canvas(self, bd=0, highlightthickness=0,bg=bg)
canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
# reset the view
canvas.xview_moveto(0)
canvas.yview_moveto(0)
self.canvasheight = 2000
# create a frame inside the canvas which will be scrolled with it
self.interior = interior = Frame(canvas,height=self.canvasheight,bg=bg)
interior_id = canvas.create_window(0, 0, window=interior,anchor=NW)
# track changes to the canvas and frame width and sync them,
# also updating the scrollbar
def _configure_interior(event):
# update the scrollbars to match the size of the inner frame
size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
canvas.config(scrollregion="0 0 %s %s" % size)
if interior.winfo_reqwidth() != canvas.winfo_width():
# update the canvas's width to fit the inner frame
canvas.config(width=interior.winfo_reqwidth())
interior.bind('', _configure_interior)
def _configure_canvas(event):
if interior.winfo_reqwidth() != canvas.winfo_width():
# update the inner frame's width to fill the canvas
canvas.itemconfigure(interior_id, width=canvas.winfo_width())
canvas.bind('', _configure_canvas)
self.offset_y = 0
self.prevy = 0
self.scrollposition = 1
def on_press(event):
self.offset_y = event.y_root
if self.scrollposition < 1:
self.scrollposition = 1
elif self.scrollposition > self.canvasheight:
self.scrollposition = self.canvasheight
canvas.yview_moveto(self.scrollposition / self.canvasheight)
def on_touch_scroll(event):
nowy = event.y_root
sectionmoved = 15
if nowy > self.prevy:
event.delta = -sectionmoved
elif nowy < self.prevy:
event.delta = sectionmoved
else:
event.delta = 0
self.prevy= nowy
self.scrollposition += event.delta
canvas.yview_moveto(self.scrollposition/ self.canvasheight)
self.bind("", lambda _: self.bind_all('', on_press), '+')
self.bind("", lambda _: self.unbind_all(''), '+')
self.bind("", lambda _: self.bind_all('', on_touch_scroll), '+')
self.bind("", lambda _: self.unbind_all(''), '+')
python触屏模块_触摸屏滚动Tkinter Python相关推荐
- python利用写模块_使用C++编写python扩展模块
简介 长话短说,这里说的扩展Python功能与直接用其它语言写一个动态链接库,然后让Python来调用有点不一样(虽然本质是一样的).而是指使用Python本身提供的API,使用C++来对Python ...
- python安装redis模块_安装redis及python redis模块
第一部分:安装redis mkdir /usr/local/redis cd /usr/local/src wget http://download.redis.io/releases/redis-2 ...
- python导入matplotlib模块_从NumPy导入python子模块有什么区别,matplotlib包
参见英文答案 > Importing packages in Python 5个 当我尝试使用matplotlib的pypl ...
- python分为哪几个模块_干货:入门Python重点学哪几个模块才能成为高手?
终于有时间写写作业了,入门python算是入了好几次了吧,包括自学的,其他课程学的.因为这关的基础之前我已经学过好几遍了,很多代码我就不放了,这里主要把入门经验交流分享下. python算是我接触到的 ...
- python通达信模块_通达信转python
好转,学会以下操作就很容了. 得到当前工作目录,即当前Python脚本工作的目录路径:os.getcwd() 返回指定目录下的所有文件和目录名:os.listdir() 函数用来删除一个文件:os.r ...
- python 命令行 模块_深入浅析Python 命令行模块 Click
Click 是用 Python 写的一个第三方模块,用于快速创建命令行.我们知道,Python 内置了一个 Argparse 的标准库用于创建命令行,但使用起来有些繁琐,Click 相比于 Argpa ...
- python安装django模块_在您的(Django)项目中使用setup.py
Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发. 最近一位客户问我为什么我们创建的Django项目的根目录下都有一个setup.py.其他很多项目没有set ...
- android触屏压力方案,触摸屏实现原理与在android上实现.doc
PAGE 6 武汉工程大学邮电与信息工程学院毕业设计(论文) 武汉工程大学邮电与信息工程学院 毕业设计(论文) 触摸屏的实现原理及在android上的实现 The Principle of the T ...
- python中常用模块_工作中用过的Python常用模块:(基于3.x)
内置模块: sys 用于提供对解释器相关的访问及维护.例如:sys.argv --传参 sys.platform --返回系统平台名称 sys.version --查看python版本 os 用于提供 ...
最新文章
- Silverlight WCF RIA服务(二十三)Silverlight 客户端 4
- html table 表格 行合并 列合并
- 最基本的弹出窗口代码
- css中position属性(absolute/relative/static/fixed)
- React Native(四)——顶部以及底部导航栏实现方式
- 大数据概念思维导图_【数据整理】一份思维导图,学完Tableau Prep(下)
- 通信电子电路实验(三)——高频电容反馈型LC振荡器的设计与仿真
- ae去闪插件deflicker使用_夜晚视频灯光去闪烁 Deflicker插件
- 这次是100秒 蓝箭航天80吨液氧甲烷发动机100%推力试车
- 微型计算机结构五大,微型计算机的体系结构
- 数智融合加速驱动企业商业创新
- 哈尔滨理工大学第七届程序设计竞赛决赛(网络赛-高年级组)G - 幼儿园战争...
- 快速上手 Spring Boot 项目开发
- DIY空气检测仪:攀藤G5ST分析仪
- 把软件装进U盘,真正做到即插即用
- scrapy框架之shell
- c++小游戏合集(AI)
- python使用tkinter库,封装操作excel为GUI程序
- 29家骗子购物网站被曝光
- 双目摄像头(CSI-IMX219)的标定
热门文章
- simpleCaptcha语音验证码实现及其扩展
- 仿照中国银行页面进行编写,主要涉及到float,定位
- Flutter for ble 之set_notification_error, could not locate CCCD descriptor for characteristic分析(原生角度)
- 清华王牌专业建系70年,撑起中国半导体半壁江山,王兴李健都是系友
- 《德鲁克管理思想精要》读书笔记2 - 企业的宗旨、目标
- amCharts使用方式
- 股票 市盈率(PE)
- python怎么加图片_python如何增加背景图片
- WS2812C IO口模拟控制
- 码农与程序员,就好比哈士奇与狼