question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider an alternative to extending tk classes

See original GitHub issue

A 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:

screenshot from 2017-08-21 12-18-03

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:

screenshot from 2017-08-21 12-43-57

Somewhat related to @martinohanlon’s #25

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bennuttallcommented, Oct 3, 2017
pip install ipython

It’s just like the Python shell but better (no harder to use) 👍

0reactions
lawsiecommented, Nov 6, 2017

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Tkinter: Working with Classes - DigitalOcean
Extending from the tk.Tk class allows us to work with components that are present in the Tk() class. 1. Initializing the classes. In...
Read more >
Transitional Kindergarten Basics • TKCalifornia
find some helpful information on the basics to help design your Transitional Kindergarten (TK) program as it is expanded to all 4-year-olds in...
Read more >
Transitional Kindergarten Implementation Guide
TK teachers should consider the individual interest levels and learning modalities of each student to ensure involvement in each lesson.
Read more >
California transitional kindergarten: Moving too fast?
Last year, Gov. Gavin Newsom announced a $2.7 billion initiative to expand transitional kindergarten to all 4-year-olds.
Read more >
Graphical User Interfaces with Tk — Python 3.11.1 ...
It provides a robust and platform independent windowing toolkit, that is available to Python programmers using the tkinter package, and its extension, the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found