以下是用Python tkinter库实现的一个弹框,包含两个并列的按钮,可以实现一个按钮被选择后,另一个按钮不能被选择的效果:

import tkinter as tk

class MyDialog:
    def __init__(self, parent):
        top = self.top = tk.Toplevel(parent)
        tk.Label(top, text="请选择:").pack()
        self.var_disable = tk.IntVar()
        self.var_enable = tk.IntVar()
        self.chk_disable = tk.Checkbutton(top, text="Disable", variable=self.var_disable, command=self.on_disable_clicked)
        self.chk_enable = tk.Checkbutton(top, text="Enable", variable=self.var_enable, command=self.on_enable_clicked)
        self.chk_disable.pack(side=tk.LEFT)
        self.chk_enable.pack(side=tk.LEFT)

    def on_disable_clicked(self):
        if self.var_disable.get() == 1:
            self.chk_enable.configure(state=tk.DISABLED)
        else:
            self.chk_enable.configure(state=tk.NORMAL)

    def on_enable_clicked(self):
        if self.var_enable.get() == 1:
            self.chk_disable.configure(state=tk.DISABLED)
        else:
            self.chk_disable.configure(state=tk.NORMAL)

def popup():
    dialog = MyDialog(root)
    root.wait_window(dialog.top)

root = tk.Tk()
tk.Button(root, text="弹出对话框", command=popup).pack()
root.mainloop()

运行以上代码后,点击“弹出对话框”按钮可以弹出一个包含两个并列的复选框的弹框,选择其中一个复选框后,另一个复选框就会变为不可选状态

python语言写一个弹框里面有两个并列的按钮一个是disable一个是enable选择其中一个后另一个就不能选择

原文地址: https://www.cveoy.top/t/topic/fgE5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录