1

enter image description hereI have a group of buttons that work together as radiobuttons, and I try to make the last one of them open a menu like menubutton Or at least make the menubutton separate and make it work by clicking a button in the radiobuttons group

menubutton does not accept value and variable

  • Hi, welcome to StackOverflow. Could you please indicate whether you're writing HTML+CSS, or using some other framework? And please show any code you've tried so far. (If you're writing HTML+CSS, I suggest looking at the tutorials on https://w3.org/) – Martin Kealey Jun 26 '23 at 04:26

1 Answers1

0

I made a simple example with the concept you describe

import tkinter as tk

root = tk.Tk()

popup = tk.Menu(root, tearoff=0)
popup.add_command(label="Popup1")
popup.add_command(label="Popup2")


def popup_command(btn):
    try:
        x = btn.winfo_rootx()
        y = btn.winfo_rooty()
        popup.tk_popup(x, y, 0)
    finally:
        popup.grab_release()


v = tk.StringVar(root, "1")
values = {"Standard Button 1": "1",
          "Standard Button 2": "2",
          "Standard Button 3": "3",
          "Standard Button 4": "4",
          "Pop-out menu button": "5"}

for text, value in values.items():
    btn = tk.Radiobutton(root, text=text, variable=v, value=value)
    if value == "5":
        btn.configure(command=lambda: popup_command(btn))
    btn.pack()

root.mainloop()
oskros
  • 3,101
  • 2
  • 9
  • 28