11

I have written a program in Python with a tkinter GUI front-end. When this is run from the script there are no issues.

I packaged it using cx_freeze to an exe file and running it from there works for the majority of the program. However, it has a problem: when trying to assign a value to a StringVar object in one of the functions an exception is raised and kills the program.

When the same function is accessed from a different point in the program it functions normally. Any idea what could be wrong?

The section of code that causes the issue is as follows (I added the messagebox so I could see what it failed on):

if keyDetail.get('default', False):
    try:
        self.entries[key].set(keyDetail['default'])
    except Exception as err:
        messagebox.showinfo('error', 'key: %s, default: %s, error: %s'%(key, keyDetail['default'], err))

self.entries[key] is a tk.StringVar.

When this is run, I get the following message in the messagebox:

key: orderNo, default: Order Number, error: can't set "PY_VAR16:0"

KevinOrr
  • 1,663
  • 3
  • 13
  • 24
Holloway
  • 6,412
  • 1
  • 26
  • 33
  • I'm not sure why Tcl would fail to set a value for a variable which is not array, because it would end up creating a variable even if it didn't exist. But, if it is not too late for your program, my tip is to drop the usage of Tcl variables; you don't need that in your Python code. Also, do you like global variables ? When you create a Tcl variable through Tkinter, you are always creating global variables (without you explicitly knowing). If you were in pure Tcl code then creating (local) variables is a must, but you already have such things in Python. You can arrange to use Tkinter with them. – mmgp Dec 21 '12 at 01:03
  • @mmgp you do need the Tcl variables for things like firing events when a variable changes. – korylprince Jun 09 '13 at 06:52
  • @Trengot — can you paste the other parts of your code here, or onto pastebin? I think the things above is not enough to catch the problem.. – Peter Varo Jul 05 '13 at 12:47
  • @Peter Varo Sorry for not updating this sooner, I eventually traced the issue back to another part of the code entirely where the keyDetail['default'] value was not being set to a valid value when given an obscure collection of conditions I'd not seen could occur simultaneously. – Holloway Jul 08 '13 at 12:00

0 Answers0