Gumboil
Posts: 44
Joined: Thu Dec 25, 2014 10:20 pm

tkinter widget not responding

Sun Feb 01, 2015 10:53 pm

I have a simple process which doesn't do what I want.

Press a ttk.Button. Processing transfers to the Button command function
In that function set the text of a ttk.Label via the StringVar() variable e.g. "Processing Started"
Do a load of processing
set the ttk.Label text to "Processing Finished" as the last action of the function.

This doesn't work. It appears that the Label texts are only set after the Button function has completed, and processing
transfers to the mainloop. So the first text, if it appears at all, is overtaken by the second text.
Ideally I would like to have a progress bar in the function, but this doesn't work either.
What am I doing wrong? Can someone help please?

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: tkinter widget not responding

Sun Feb 01, 2015 11:08 pm

Post your code, wrap it in [code] your code goes here[/code] tags.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Gumboil
Posts: 44
Joined: Thu Dec 25, 2014 10:20 pm

Re: tkinter widget not responding

Tue Feb 03, 2015 11:35 am

Hi Dougie,
I hope I have copied this code in correctly - it is the first time I have done it.
The code is a modified extract from a much large program but demonstrates my problem, which is "how do I get the first message to appear". The code is executable under IDLE python3.

Code: Select all

[#! /usr/bin/python3
from tkinter import *
from tkinter import ttk

root = Tk()
mf = ttk.Frame(root, borderwidth=1, relief='solid', padding="3 3 12 12")
mf.grid(column=0, row=1, sticky=(W, E))
mf.columnconfigure(0, weight=1)
mf.rowconfigure(0, weight=1)
def getDataf(*args):
    getData.set('Started')
##    lots of processing here simulated below
    for i in range(0, 5000000):
        x= (2.74124 ** 3.7623) ** 0.0127
    getData.set('Finished')
getData = StringVar()
getDataButton = ttk.Button(mf, command=getDataf, text='Press Me')
getDataButton.grid(column=0, row=1, pady=5, columnspan=3, sticky=(E))
getDataLabel = ttk.Label(mf, foreground='blue', textvariable=getData, anchor='center')
getDataLabel.grid(column=0, row=2, pady = 5, sticky=(W, E))
root.mainloop()
]

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: tkinter widget not responding

Tue Feb 03, 2015 11:45 am

When I removed the [ & ] and fixed the #! shebang line your code worked first go for me. That's on Raspbian Wheezy (up to date as at 09:00 this morning) running on my A+ using VNC from my laptop (so I don't have to visit the machine).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Gumboil
Posts: 44
Joined: Thu Dec 25, 2014 10:20 pm

Re: tkinter widget not responding

Tue Feb 03, 2015 7:23 pm

I'm a bit stuck now. I did an update and upgrade to ensure my Wheezy system is up to date. I am running on a Mac using VNC. Still didn't work. Also tried on a directly attached k/b, mouse and screen. Same result. I'm using a B+ but don't have an A+ like you try it on. The patch level of tkinter is 8.5.11. Any ideas?

Return to “Python”