chenjl1 发表于 2022-8-30 19:17:40

【提问】Tkinter中Radiobutton传参的代码

在Entry组件中, validatecommand=(tesCMD, '%P')可以实现自动读取输入用于自定义函数
Raiobutton有没有类似的功能?

python爱好者. 发表于 2022-8-31 07:23:02

有,只是小甲鱼课上没讲import tkinter as tk

root = tk.Tk()
v = tk.IntVar()

def buttonback():
      print(f"选中结果:{v.get()}")

tk.Radiobutton(root,text = "点我~",variable = v,value = 1,command = buttonback).grid(row = 0,column = 0)
tk.Radiobutton(root,text = "点我!",variable = v,value = 2,command = buttonback).grid(row = 0,column = 1)


页: [1]
查看完整版本: 【提问】Tkinter中Radiobutton传参的代码