2
2
OptionMenu widget modified to allow dynamic menu reconfiguration
3
3
and setting of highlightthickness
4
4
"""
5
- import copy
6
-
7
5
from tkinter import OptionMenu , _setit , StringVar , Button
8
6
9
7
class DynOptionMenu (OptionMenu ):
10
- """
11
- unlike OptionMenu, our kwargs can include highlightthickness
8
+ """Add SetMenu and highlightthickness to OptionMenu.
9
+
10
+ Highlightthickness adds space around menu button.
12
11
"""
13
12
def __init__ (self , master , variable , value , * values , ** kwargs ):
14
- # TODO copy value instead of whole dict
15
- kwargsCopy = copy .copy (kwargs )
16
- if 'highlightthickness' in list (kwargs .keys ()):
17
- del (kwargs ['highlightthickness' ])
13
+ highlightthickness = kwargs .pop ('highlightthickness' , None )
18
14
OptionMenu .__init__ (self , master , variable , value , * values , ** kwargs )
19
- self .config (highlightthickness = kwargsCopy .get ('highlightthickness' ))
20
- #self.menu=self['menu']
21
- self .variable = variable
22
- self .command = kwargs .get ('command' )
15
+ self ['highlightthickness' ] = highlightthickness
16
+ self .variable = variable
17
+ self .command = kwargs .get ('command' )
23
18
24
19
def SetMenu (self ,valueList ,value = None ):
25
20
"""
@@ -38,14 +33,15 @@ def _dyn_option_menu(parent): # htest #
38
33
from tkinter import Toplevel # + StringVar, Button
39
34
40
35
top = Toplevel (parent )
41
- top .title ("Tets dynamic option menu" )
36
+ top .title ("Test dynamic option menu" )
42
37
x , y = map (int , parent .geometry ().split ('+' )[1 :])
43
38
top .geometry ("200x100+%d+%d" % (x + 250 , y + 175 ))
44
39
top .focus_set ()
45
40
46
41
var = StringVar (top )
47
42
var .set ("Old option set" ) #Set the default value
48
- dyn = DynOptionMenu (top ,var , "old1" ,"old2" ,"old3" ,"old4" )
43
+ dyn = DynOptionMenu (top , var , "old1" ,"old2" ,"old3" ,"old4" ,
44
+ highlightthickness = 5 )
49
45
dyn .pack ()
50
46
51
47
def update ():
@@ -54,5 +50,6 @@ def update():
54
50
button .pack ()
55
51
56
52
if __name__ == '__main__' :
53
+ # Only module without unittests because of intention to replace.
57
54
from idlelib .idle_test .htest import run
58
55
run (_dyn_option_menu )
0 commit comments