2

I was trying to make a subclass that acts like the original but its go function returned the string of the text of the button, instead of the index of the button.

My own defined subclass makes the second, third, and so forth buttons rectangular. Also - My OS is macOS 15.5. Tkinter version is 8.6.14.

Original tkinter.simpledialog.SimpleDialog Result in the Test: Original tkinter.simpledialog.SimpleDialog Result in the Test

My defined Subclass' Result in the Test: My defined Subclass' Result in the Test

from tkinter import simpledialog, Tk
class SimpleDialog(simpledialog.SimpleDialog):
    def __init__(self, master, text='', buttons=None, default=0, cancel=None, title=None, **kw):
        self.buttons = buttons or []
        super().__init__(master, text=text, buttons=buttons, default=default, cancel=cancel, title=title, **kw)
    def go(self) -> str:
        return self.buttons[super().go()]

buttons = ['hi', 'yo']

simpledialog.SimpleDialog(master = Tk(), buttons = buttons).go() # Result: A dialog that shows buttons ('hi', 'yo') of curved edges
SimpleDialog(master = Tk(), buttons = buttons).go()
# Expected Result: A dialog that shows buttons ('hi', 'yo') of curved edges
# Actual Result: A dialog that shows the first button, 'hi', but the second button, 'yo', is slightly longer and the edges are pointed (like a rectangle)

Tried adding more buttons to the list or having a button with a long text. Didn't work.

No idea why my new subclass' first button has its edges curved, but the second and so forth buttons look rectangular, but the original has its edges curved for all buttons. There were no errors though.

6
  • Try passing in default=None to both SimpleDialog and simpledialog.SimpleDialog. If the problem persist, it's most likely a bug in tcl (what tkinter interfaces with to create/manipulate windows/widgets) Commented Jun 15 at 9:56
  • @TheLizzard It worked! Thank you! But why do I need to put a default = None into my defined subclass, unlike the original? Commented Jun 15 at 10:09
  • originial code for SimpleDialog has default=None but your class uses default=0 and maybe it makes difference for tcl Commented Jun 15 at 10:32
  • In tkinter's source code, tkinter calls .config(relief=RIDGE, borderwidth=8) on the default button. For some reason that messes with the other buttons and removes their roundness. I suspect this is actually a bug in tcl but I have no way of testing it Commented Jun 15 at 10:34
  • Whoops. Nevermind - I accidentally put default = 0 in my subclass. Sorry 😅. But yeah I guess it's a module bug when default = 0. Commented Jun 16 at 3:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.