python - 如何判断按钮是否在 tkinter 中被抬起
问题描述
我问如果 Tkinter 窗口中有几个按钮,其中一些按钮是 FLAT 并且一些按钮是 RAISED 的。我想要一个函数来知道按钮是凸起的还是平的。
请帮忙
提前致谢
解决方案
解决方案:
tkinter
按钮具有浮雕属性,指定按钮是否为SUNKEN、RAISED、GROOVE 和 RIDGE。
这是您应该如何检查按钮是凸起还是平坦的:
import tkinter as tk
def RaisedOrFlat(buttonName):
button = buttonName
# check if the button is Raised
if button['relief']== "raised":
return 'raised'
# check if the button is flat
elif button['relief'] == "flat":
return 'flat'
#Creates the form
main = tk.Tk()
#creates the button
btn1 = tk.Button(main, text='Button 1', relief="raised")
btn1.pack()
#call the function
if RaisedOrFlat(btn1) == 'flat':
print('flat')
elif RaisedOrFlat(btn1) == 'raised':
print('raised')
main.mainloop()
输出:raised
推荐阅读
- selenium - 如何使用 gocolly twocaptcha 和 selenium 绕过重新验证码
- javascript - Bootstrap 5 - 以编程方式打开导航选项卡
- ios - 是否可以在 NSTimer 到达指定时间之前停止它?
- reactjs - 文本字段在表格 ReactJs 中无法正常工作
- html - 引导(AdminLTE)文件上传向导未在复选框中显示上传的文件名
- javascript - 如何调用另一个组件函数?
- python - 断开音乐机器人与语音通道的连接
- http - 在 Go 中发送未编码的 GET 请求
- python - 具有页面限制的网页抓取
- vue.js - nuxt generate 后css更改