028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

Python中tkinter事件绑定操作的示例分析-创新互联

小编给大家分享一下Python中tkinter事件绑定操作的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都做网站、网站设计、外贸营销网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的大观网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!python有哪些常用库

python常用的库:1.requesuts;2.scrapy;3.pillow;4.twisted;5.numpy;6.matplotlib;7.pygama;8.ipyhton等。

相关内容:

首发时间:2018-03-04 19:26


command:
from tkinter import *
root=Tk()

def prt():
  print("hello")
def func1(*args,**kwargs):
  print(*args,**kwargs)
hello_btn=Button(root,text="hello",command=prt)#演示
hello_btn.pack()

args_btn=Button(root,text="获知是否button事件默认有参数",command=func1)#获知是否有参数,结果是没有

args_btn.pack()
btn1=Button(root,text="传输参数",command=lambda:func1("running"))#强制传输参数

btn1.pack()

root.mainloop()

bind:
from tkinter import *
root=Tk()
root.geometry("200x200")
text=Text(root)
text.pack()

def func(event):
  print(event)
def func_release(event):
  print("release")
#单击
# text.bind("",func)
# root.bind("",func)
#双击
# text.bind("",func)
# 鼠标释放
# text.bind("",func_release)
#鼠标移入
# text.bind("",func)
#鼠标按住移动事件
# text.bind("",func)
#键盘按下事件
# text.bind("",func)

#键位绑定事件
# def func3(event):
#   print("你按下了回车!")
# text.bind("",func3)


#实现的一个拖拽功能
def func4(event):
  # print(event)
  x=str(event.x_root)
  y=str(event.y_root)
  root.geometry("200x200+"+x+"+"+y)

text.bind("",func4)




root.mainloop()

补充:如果想要传参,可以使用lambda:

text.bind("",lambda event:func(event,"hello"))

 Python中tkinter事件绑定操作的示例分析

Python中tkinter事件绑定操作的示例分析


protocol:
from tkinter import *
import tkinter.messagebox
root=Tk()
root.geometry("200x200")
def func1():
  if tkinter.messagebox.askyesno("关闭窗口","确认关闭窗口吗"):
    root.destroy()

root.protocol("WM_DELETE_WINDOW",func1)

root.mainloop()

以上是“Python中tkinter事件绑定操作的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


分享文章:Python中tkinter事件绑定操作的示例分析-创新互联
链接地址:http://www.tsicrk.com/article/cspege.html

其他资讯

让你的专属顾问为你服务

2.3552s