m0_57901298 2021-05-05 19:27 采纳率: 58.3%
浏览 11

tkinter event 冲突

tkinter <Button-1> <ButtonPress-1> <ButtonRelease-1>冲突

def link(textobj, place, color, underline, execcmd, var):
	exec('textobj.tag_add(var, place[0], place[1])')
	exec('textobj.tag_config(var, foreground = color[0], background = color[1], underline = underline)')
	textobj.config(cursor = 'arrow')
	def show_hand_cursor(event):
		textobj.config(cursor = 'hand2')
	
	def show_xterm_cursor(event):
		textobj.config(cursor = 'xterm')
	
	def onclick(event):
		nonlocal execcmd
		exec(execcmd)
	
	def onmousedown(event):
		nonlocal textobj, var, color
		exec('textobj.tag_config(var, foreground = color[3], background = color[1])')
	
	def onmouseup(event):
		nonlocal textobj, var, color
		exec('textobj.tag_config(var, foreground = color[2], background = color[1])')
	
	exec("textobj.tag_bind(var, '<Enter>', show_hand_cursor)")
	exec("textobj.tag_bind(var, '<Leave>', show_xterm_cursor)")
	exec("textobj.tag_bind(var, '<Button-1>', onclick)")
	exec("textobj.tag_bind(var, '<ButtonPress-1>', onmousedown)")
	exec("textobj.tag_bind(var, '<ButtonRelease-1>', onmouseup)")
  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-07 17:30
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥20 ARM64架构下SSCMS部署问题
  • ¥20 请教如何让移动端的热区自适应
  • ¥30 为什么深度学习网络训练会出现训练集和测试集准确率和损失都不变的情况
  • ¥15 (标签-3D|关键词-色模型)
  • ¥15 发现在MSVS2022中”#pragma once“不起作用
  • ¥15 实时声纹降噪算法进行无关说话人语音抑制
  • ¥100 adb针对解决手机锁屏问题(相关搜索:手机锁屏)
  • ¥15 发现哔哩哔哩的粉丝只能显示前5页能不能爬出来
  • ¥15 oracle数据库求解
  • ¥15 c++ websocketpp连接币安 有报错,有偿求解