Consider an alternative to extending tk classes
See original GitHub issueA suggestion: rather than extend tk classes, would you consider creating new classes where the tk object is exposed as a property, so that only the guizero goodness is exposed to most users, but those who wish to (forgive me) tinker below the surface can still get to the nasty tk stuff?
The tk stuff is messy and most of it isn’t useful. Using tab completion to find property and methods you’re looking for is really difficult:
For example:
class Slider:
def __init__(self, master, start=0, end=100, horizontal=True, command=None, grid=None, align=None):
orient = HORIZONTAL if horizontal else VERTICAL
self.tk = Scale(master, from_=start, to=end, orient=orient, command=command)
utils.auto_pack(self, master, grid, align)
@property
def value(self):
return (self.tk.get())
@value.setter
def value(self, value):
self.tk.set(value)
def add_command(self, command):
self.tk.config(command=command)
So instead of inheriting Scale
and running super()__init__()
you create a tk Scale
object belonging to the guizero Slider
object. You would provide guizero alternatives to anything useful within the tk object, such as value
and add_command
as shown. Any methods which need access to the tk object just refer to self.tk
instead of self
.
The result:
Somewhat related to @martinohanlon’s #25
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top GitHub Comments
It’s just like the Python shell but better (no harder to use) 👍
Well, I have various other things that are unfinished and might not work - in particular the
after()
method, and some other extras I want to add. However I think I’ve successfully converted all of the classes to have an internal tk object!