2019年9月15日 / 2,667次阅读 / Last Modified 2019年9月15日
tkinter
用Python编写GUI程序,首选tkinter库。有的时候,我们需要修改鼠标落在各种控件上的样式,比如可以点击的Label和Button,可以将鼠标修改为一个可以点击的手的样子,以提示用户此处可点击;或者将鼠标显示为“繁忙”的提示信息等。
只需要修改控件的cursor属性。
import tkinter as tk
root = tk.Tk()
lb = tk.Label(text='cursor: ', font=('',32,''), cursor='circle')
lb.pack()
root.mainloop()
上面的代码,在一个Label控件上指定鼠标样式为circle,效果就是一个白色的圈。(无法截屏,PrtSc也无效)
首先要清楚,在不同的操作系统中,鼠标样式都会不太一样。默认的样式是arrow。很可能会遇到系统不支持的情况,这时就是现实默认样式。下面是样式列表(一行写两个,copy自别的网页):
arrow man based_arrow_down middlebutton based_arrow_up mouse boat pencil bogosity pirate bottom_left_corner plus bottom_right_corner question_arrow bottom_side right_ptr bottom_tee right_side box_spiral right_tee center_ptr rightbutton circle rtl_logo clock sailboat coffee_mug sb_down_arrow cross sb_h_double_arrow cross_reverse sb_left_arrow crosshair sb_right_arrow diamond_cross sb_up_arrow dot sb_v_double_arrow dotbox shuttle double_arrow sizing draft_large spider draft_small spraycan draped_box star exchange target fleur tcross gobbler top_left_arrow gumby top_left_corner hand1 top_right_corner hand2 top_side heart top_tee icon trek iron_cross ul_angle left_ptr umbrella left_side ur_angle left_tee watch leftbutton xterm ll_angle X_cursor lr_angle
没找到对应的图片,有一个nmt.edu的页面打不开了。各位可以通过上面的示例代码,修改cursor值,一个个看是否是自己需要的。常用的就那么几个,很快就试出来了。
-- EOF --
本文链接:https://www.pynote.net/archives/1135
《tkinter中的cursor鼠标样式》有2条留言
前一篇:让Label像Button一样可以点击
后一篇:filter函数
©Copyright 麦新杰 Since 2019 Python笔记
您好,我把此文中提到的所有cursor样式展示出来做了视频,链接如下 b23.tv/XmmWkz,不知是否需要demo源码 [ ]
不需要,你已留下链接了。 [ ]