Python 3 tkinter not working?

I have been programming some login code for my program and when I run it it shows a gray screen. I am using logger and that doesn't seem to report anything as well as the console not reporting any problems.

This is all of my login code minus the executing part which is in another file.

OS: Ubuntu Gnome
Python version 3.5

Don't put the class definition in a try-except-clause.

1 Like

I have just removed the try-except and still just a gray window.
Heres the logger output:

Comment out those lines in your constructor:

self.createBackground()
self.createIcon()
self.createWidgets()

Is the result what you would expect after calling: self.createWindow() ?

I don't get anything if i comment out them lines and reports no errors and not even an window anymore.

callback should create a file called "active" and has the username stored in it

Your log should look like this:

INFO:JDE.py:Importing tkinter
INFO:JDE.py:Import Successful
INFO:JDE.py:Importing JDE/Interfaces/login
INFO:JDE.py:Import Successful!
DEBUG:login.py:Running init
DEBUG:login.py:Running createWindow

Doesn't it?

Yes that is exactly what it looks like.

Fantastically. So the next step is to uncomment

self.createBackground()

Then your log should look like this:

INFO:JDE.py:Importing tkinter
INFO:JDE.py:Import Successful
INFO:JDE.py:Importing JDE/Interfaces/login
INFO:JDE.py:Import Successful!
DEBUG:login.py:Running init
DEBUG:login.py:Running createWindow
DEBUG:login.py:Running createBackground

Then ask yourself again: Is this what you would expect createWindow and createBackground to do?

Yes the log looks like that and yes i would expect the createWindow and createBackground to create a window with the background on it.

I have also changed the createBackground to look like this:

try:
self.background_image = PhotoImage(file=self.bg)
self.canvas.create_image(0, 0, image=self.background_image, anchor=NW)
self.canvas.pack(expand=YES, fill=BOTH)
except Exception as e:
loginLog.error(str(e))

The log now reports something different!

INFO:JDE.py:Importing tkinter
INFO:JDE.py:Import Successful
INFO:JDE.py:Importing JDE/Interfaces/login
INFO:JDE.py:Import Successful!
DEBUG:login.py:Running init
DEBUG:login.py:Running createWindow
DEBUG:login.py:Running createBackground
ERROR:login.py:Too early to create image

How would I go about fixing this?

Referring to this:

you need to call pack before you call create_image.

Also: Changing the category of this topic from Software & Operating Systems to Code would make sense.

Haha, unless you get to the...

self.canvas.pack(expand=YES, fill=BOTH)

...in the createBackground function's "try", you aint got no canvas packed. Doesn't happen anywhere else - the...

self.canvas.create_image(0, 0, image=self.background_image, anchor=NW)

...line will scream and throw you straight at that except before it happens, unless you've got the background image. Otherwise it'll give you a...

_tkinter.TclError: value for "-file" missing

...(but it won't in that try and except statement, just skips along to the except).

Fix: move it out of that try statement/stick it at the top of it. Preferably take it out, stick it in the createWindow function maybe. It doesn't have to be after you add that image, for me at least it doesn't make any difference, after testing using a png of a cat as a background (lol).

I hope my useless teenage potato mind at 1:30AM helped. I just saw it as an opportunity to post cat pics.

bump? @jordonbc was that right? Or...?