0

I tried to change the state of the ScaleEntry widget from the ttkwidgets package. Changing the state of the entry was easy enough.

scaleEntry.config_entry(state='disabled')
scaleEntry.config_entry(state='!disabled')

However, the scale part seems to be working differently. I tried configuring the same way as the entry scaleEntry.config_scale(state='disabled') and also tried through the configure method. It seems like in both cases, the "state" option is unknown. Even though the scale version from tkinter can be disabled in a specific way, the scale from ttkwidgets does not seem to work the same way.

Master3gg
  • 43
  • 1
  • 6
  • 1
    All tk widgets should be disabled the same way. `widget.config(state='disabled')` or `widget['state'] = 'disabled'`. I don't think `'enabled'` works. It should be `'normal'` to enable the widget. For ttk widgets you may need to use the `state` method. so `ttk_widget.state(['disabled'])`. Bryan Oakley made a [post here](https://stackoverflow.com/a/30736732/7475225) that may clear it up. – Mike - SMT Feb 10 '20 at 18:10
  • 1
    @BryanOakley I believe this question should be re-opened as this post is specifically about the library `ttkwidgets` and thus is not a duplicate post. – Mike - SMT Feb 11 '20 at 16:44
  • 2
    @Mike-SMT: thanks for noticing that. – Bryan Oakley Feb 11 '20 at 18:35

1 Answers1

2

Update:

Based on your comment below you are looking at widgets from the ttkwidgets library.

Based on this I did some digging on both their docs site and in the code itself and found there is no defined method to disable the widget.

Based on this section of code:

enter image description here

I am able to print out all possible arguments for the ScaleEntry by using .keys().

Example code:

from ttkwidgets import ScaleEntry
import tkinter as tk


window = tk.Tk()
scaleentry = ScaleEntry(window, scalewidth=200, entrywidth=3, from_=0, to=20)
scaleentry.config_entry(justify='center')
print(scaleentry.keys())
scaleentry.pack()
window.mainloop()

Key results:

['borderwidth', 'class', 'compound', 'cursor', 'entryscalepad', 'entrywidth', 'from', 'height', 'orient', 'padding', 'relief', 'scalewidth', 'style', 'takefocus', 'to', 'width']

From the list and scanning the code for ScaleEntry no such argument exist to disable this scale. So I almost came to the conclusion that it was not possible. However after reading into the code that makes up the ScaleEntry class I found this line:

enter image description here

I realize we can still disable it by targeting the internal class attribute _scale for the win! This is because at the end of the day the ScaleEntry widget is simply a tk Frame that has 2 class attributes. A ttk.Scale and a ttk.Entry.

Example:

from ttkwidgets import ScaleEntry
import tkinter as tk


window = tk.Tk()
state = True
scaleentry = ScaleEntry(window, scalewidth=200, entrywidth=3, from_=0, to=20)
scaleentry.config_entry(justify='center')
print(scaleentry.keys())
scaleentry.pack()


def toggle_state():
    global state
    if state:
        scaleentry._scale.state(['disabled'])
        scaleentry._entry.state(['disabled'])
        state = False
    else:
        scaleentry._scale.state(['!disabled'])
        scaleentry._entry.state(['!disabled'])
        state = True


tk.Button(window, text='Toggle Scale', command=toggle_state).pack()
window.mainloop()

Example before toggle:

enter image description here

Example after toggle:

enter image description here

Mike - SMT
  • 14,784
  • 4
  • 35
  • 79
  • I understand, I was not clear enough, I am not referring to tkinter.ttk. I was talking about the package literally called ttkwidgets... In other words, the ScaleEntry widget is imported as `from ttkwidgets import ScaleEntry` which has some nuances in the mechanic of the widget. As I was saying, I am only able to disable the entry part through `scaleEntry.config_entry(state='disabled')` but not the scale part. Your method does not work here... – Master3gg Feb 11 '20 at 15:45
  • Then you will want to update your tags. That should help clear up the confusion. – Mike - SMT Feb 11 '20 at 15:55
  • That was exactly how far I got. Thank you for your help it is appreciated. – Master3gg Feb 11 '20 at 16:27
  • 1
    @Master3gg I just make an update I think you will be pleased with :D – Mike - SMT Feb 11 '20 at 16:37
  • 1
    Wow! That is exactly what I was looking for, I knew that it could be analysed as 2 separate attribute, but I clearly did not know how to isolate the case! You just taught me something new. I just started coding python 3 weeks ago, that's why I am still not pro at it, but i love it. Thank you again! :) – Master3gg Feb 11 '20 at 16:55
  • 1
    @Master3gg Glad to help. Most of the time there is documentation somewhere or at least another post that has a related problem but sometimes a little digging can reveal the light at the end of the tunnel :D – Mike - SMT Feb 11 '20 at 17:07