Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tkinter Dialog fails when more than four buttons are used #43009

Closed
hernanpd mannequin opened this issue Mar 10, 2006 · 8 comments
Closed

tkinter Dialog fails when more than four buttons are used #43009

hernanpd mannequin opened this issue Mar 10, 2006 · 8 comments
Assignees
Labels
topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@hernanpd
Copy link
Mannequin

hernanpd mannequin commented Mar 10, 2006

BPO 1447222
Nosy @loewis, @asvetlov, @berkerpeksag, @csabella
Files
  • Dialog_workaround.diff
  • test_dialog.py
  • example.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/loewis'
    closed_at = <Date 2017-10-29.03:27:45.824>
    created_at = <Date 2006-03-10.13:54:22.000>
    labels = ['type-bug', 'expert-tkinter']
    title = 'tkinter Dialog fails when more than four buttons are used'
    updated_at = <Date 2017-10-29.03:27:45.810>
    user = 'https://bugs.python.org/hernanpd'

    bugs.python.org fields:

    activity = <Date 2017-10-29.03:27:45.810>
    actor = 'berker.peksag'
    assignee = 'loewis'
    closed = True
    closed_date = <Date 2017-10-29.03:27:45.824>
    closer = 'berker.peksag'
    components = ['Tkinter']
    creation = <Date 2006-03-10.13:54:22.000>
    creator = 'hernanpd'
    dependencies = []
    files = ['10485', '14401', '47244']
    hgrepos = []
    issue_num = 1447222
    keywords = ['patch']
    message_count = 8.0
    messages = ['60883', '67054', '67064', '67578', '76128', '89895', '300910', '305173']
    nosy_count = 6.0
    nosy_names = ['loewis', 'hernanpd', 'gpolo', 'asvetlov', 'berker.peksag', 'cheryl.sabella']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1447222'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @hernanpd
    Copy link
    Mannequin Author

    hernanpd mannequin commented Mar 10, 2006

    Example code:

    #! /usr/bin/env python
    import Dialog
    from Tkinter import *
    root = Tk()
    Button(root, text="Hello!").pack()
    root.update()
    dialog = Dialog.Dialog(None, {'title': 'Test Dialog',
              'text': "Text...",
              'bitmap': '',
              'default': 0,
              'strings':
    ('Button0','Button1','Button2','Button3','Button4')})
    print 'dialog: ', dialog.num
    This example works well, except when clicking in
    Button4 that fails:
    Traceback (most recent call last):
      File "test.py", line 12, in ?
        dialog = Dialog.Dialog(None, {'title': 'Test Dialog',
      File "/usr/lib/python2.3/lib-tk/Dialog.py", line 21,
    in __init__
        cnf['bitmap'], cnf['default'],
    TypeError: getint() argument 1 must be string, not tuple

    I tried to trace the error (learning in the way a
    little bit of python and tcl/tk ;)), mostly due to the
    bizarre nature of this problem (note that in tcl/tk
    there are no problems when creating dialogs with 4 or
    more buttons).

    In /usr/lib/python2.3/lib-tk/Dialog/py the exception is
    raised because it expects a string as the result to the
    call to 'tk_dialog', and for some 'obscure' reason (and
    I mean it, I even inspected the Tcl/Tk sources looking
    for a reason for this) if the call to 'tk_dialog' has
    more than 4 buttons (more than 4 string arguments at
    the end) it return a tuple with only one element, the
    string result.

    The impression I got after browsing the sources of
    python/tkinter and Tcl/Tk is that this may be caused
    because in tcl there is almost no difference between a
    list and string, in this way in the tcl language a
    string or a list containing only one string are not
    really different.

    I have this problem when using python2.3 or python2.4
    with Tcl/Tk8.4 (in my particular case under
    Debian/Testing distribution);

    A quick workaround (although I 'm not sure if it would
    cause some problems with other things) would be to
    change 'workarounds = 1' to 'workarounds = 0' in
    Tkinter.py.
    Another option would be to change all calls to tk
    functions within tkinter that allways expect as a
    result a string...

    Hernan
    (my apologies for making the report so long)

    @hernanpd hernanpd mannequin assigned loewis Mar 10, 2006
    @hernanpd hernanpd mannequin added the topic-tkinter label Mar 10, 2006
    @hernanpd hernanpd mannequin assigned loewis Mar 10, 2006
    @hernanpd hernanpd mannequin added the topic-tkinter label Mar 10, 2006
    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented May 19, 2008

    I just tried it here and it still happens, it also happens for the 11th
    button and that is it (5th and 11th). I tried it with tk 8.4 and tk 8.5,
    python-trunk, python 2.5.2.

    I'm investigating this.

    For some reason a pixel object is being returned inside a tuple.
    _tkinter detects a ListType object, then creates a tuple with one
    object, which is a pixel object and it has the value you would expect, 4
    or 10.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented May 19, 2008

    The workaround is actually setting wantobjects to 0, which I doubt
    everyone will like.
    I've talked with a tcl developer and some interesting points were raised
    from the talk:

    1. Looking at typePtr in _tkinter isn't actually good (this is used to
      convert the tcl object to a proper python object), because it may not
      work always, like in this case. But the person also mentioned he didnt't
      know of any good solutions to that problem.
    2. Cause of the problem -- most likely: something else in the code that
      creates the message box is using the literal string "5" as a
      -borderwidth or a -padding or as something else that's passed to a
      widget. And the compiler uses the same Tcl_Obj * for that "5" and the
      "5" that you pass to [tk_dialog].

    Apparently trying to fix this in Python would case some (major?) changes
    in _tkinter.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented May 31, 2008

    This is a workaround and seems to be the way to go.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Nov 20, 2008

    bpo-4333 fixes this too, btw

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Jun 30, 2009

    Interesting.. I tried testing Dialog for that bug, but generating
    <Return> keypress (you can combine with keyrelease too) doesn't trigger
    the problem (very weird to me). I will be simulating mouse clicks to see
    if, for some reason, the bug gets noticed.

    Attaching the test I tried just in case.

    @BreamoreBoy BreamoreBoy mannequin added type-bug An unexpected behavior, bug, or error labels Aug 22, 2010
    @csabella
    Copy link
    Contributor

    I tried the example code under 3.7 and it produced the correct the output. I think this issue can be closed.

    @berkerpeksag
    Copy link
    Member

    I ported OP's example to Python 3 and I agree with Cheryl that this is fixed now.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants