Skip to content

bpo-25684: ttk.OptionMenu radiobuttons aren't unique between instance… #2276

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

Merged
merged 4 commits into from
Jul 31, 2017

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Jun 19, 2017

…s of OptionMenu

Solution based on workaround by Bryan Oakley at https://stackoverflow.com/questions/33831289/ttk-optionmenu-displaying-check-mark-on-all-menus

to set the variable attribute of the OptionMenu when the radiobuttons are added.

https://bugs.python.org/issue25684

@mention-bot
Copy link

@csabella, thanks for your PR! By analyzing the history of the files in this pull request, we identified @gpolo, @serhiy-storchaka and @vadmium to be potential reviewers.

@@ -276,7 +276,25 @@ def test_menu(self):
self.assertRaises(tkinter.TclError, optmenu['menu'].invoke, -1)
self.assertEqual(optmenu._variable.get(), items[0])

# check that radiobuttons are unique across instances (bpo25684)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this test into separate method?

@serhiy-storchaka serhiy-storchaka added needs backport to 2.7 type-bug An unexpected behavior, bug, or error labels Jul 16, 2017
@serhiy-storchaka
Copy link
Member

Please add an entry in Misc/NEWS.d/next/Library/ and move the test into separate method.

@csabella
Copy link
Contributor Author

@serhiy-storchaka Thank you for the review. I've made the requested changes. It was the first time I've added a NEWS entry though, so hopefully I used blurb correctly.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is merged and backported, I will try to remember to add a note to the S.O. question.

Cheryl, this would be a good issue for learning to use cherry_picker. I believe you can install into the same venv as you used for coverage and blurb.

items[2])

optmenu.destroy()
del textvar2, optmenu_radiobutton_name, optmenu2_radiobutton_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. del just unbinds the local names. This happens anyway when the function exits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. For some reason, even though they were local, I thought that the Tk variables had to be explicitly deleted for refleaks. But, it's probably just when it's in setUp.

optmenu['menu'].invoke(1)
optmenu2['menu'].invoke(2)
optmenu_radiobutton_name = optmenu['menu'].entrycget(0, 'variable')
optmenu2_radiobutton_name = optmenu2['menu'].entrycget(0, 'variable')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume that this is actually the tk name of the StringVar that has the selected value.
If so, optmenu_stringvar_name would seem clearer. With the bug fixed, the name should be 'PY_VAR####' instead of the current ttk default '::selectedButton'.

self.assertEqual(self.root.tk.globalgetvar(optmenu_radiobutton_name),
items[1])
self.assertEqual(self.root.tk.globalgetvar(optmenu2_radiobutton_name),
items[2])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find any doc for globalgetvar other than its use in the Variable subclass get methods. It appear to be a _tkinter function that gets the value of a Variable from its name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a lot of trouble with this when I was trying to create the test. I had even asked for help on core_workflow. But, after looking through the other tests in this suite, I saw that globalgetvar gave me what I wanted. I ran the test over the old code and it failed (which was good - failed on the old and passed on the new) and I also looked at the values in debug and this was exactly what I needed. I don't know if there was any other way to get that information.

@terryjreedy
Copy link
Member

Although I approved, I also suggested a change. The last commit satisfies Serhiy request.

@terryjreedy
Copy link
Member

The release candidate for the final bugfix release of 3.5, 3.5.4, is out. Since this is not a security issue, I believe it should not be backported to 3.5

@csabella
Copy link
Contributor Author

Terry,

Yes, I can use cherry_picker to backport this once it's merged. Thanks!

@serhiy-storchaka serhiy-storchaka merged commit a568e52 into python:master Jul 31, 2017
@serhiy-storchaka
Copy link
Member

Thank you @csabella! When you will backport this PR to 3.6 and 2.7 don't forgot to add your name in Misc/ACKS.

@csabella csabella deleted the bpo25684 branch July 31, 2017 10:55
csabella added a commit to csabella/cpython that referenced this pull request Jul 31, 2017
…-2276)

between instances of OptionMenu.
(cherry picked from commit a568e52)
@bedevere-bot
Copy link

GH-2959 is a backport of this pull request to the 3.6 branch.

csabella added a commit to csabella/cpython that referenced this pull request Jul 31, 2017
between instances of OptionMenu.
(cherry picked from commit a568e52)
@bedevere-bot
Copy link

GH-2960 is a backport of this pull request to the 2.7 branch.

serhiy-storchaka pushed a commit that referenced this pull request Jul 31, 2017
…#2959)

between instances of OptionMenu.
(cherry picked from commit a568e52)

* Update Misc/ACKS
Mariatta pushed a commit that referenced this pull request Sep 10, 2017
)

ttk.OptionMenu radiobuttons weren't unique 
between instances of OptionMenu.
(cherry picked from commit a568e52)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants