-1

I'm currently trying to create a Python3 Tkinter program which I can launch by double clicking or opening from other python scripts, instead of going through idle.

So far I've had little luck, as when I attempt to launch the script the console opens for a moment and then crashes.

EDIT: Removing the logo segment of code allows the program to run. Any ideas why and how to fix it? Also I have not had to run a program via the console before so little luck there.

from tkinter import *
from tkinter import ttk

root = Tk()
root.title("Kinematics")

Logo_frame = LabelFrame(root, bg = "white")
Logo_frame.grid(row=0, column=12, sticky = "NSEW")

#Logo
Logo = Image(file="Logo-S.gif")
image_label = ttk.Label(Logo_frame, image=Logo)
image_label.grid(row=0, column=0, rowspan = 3)

root.mainloop()
L31
  • 3
  • 3
  • 2
    General debugging technique for "console opens for a moment and then crashes" problems: run the program from a console, so that you can see what the error message actually is. – jasonharper Mar 26 '18 at 03:16
  • 1
    Please don't post working code. Post code that causes the error, and then include the error in your question. – Bryan Oakley Mar 26 '18 at 04:18
  • I'm attempting to launch it without using IDLE and when I attempt that it doesn't work. That code there, specifically the #Logo sections is what appears to break it. – L31 Mar 26 '18 at 04:20

2 Answers2

0

The error from your present code is:

Exception ignored in: <bound method Image.__del__ of <tkinter.Image object at 0x7f1aa91df2e8>>
Traceback (most recent call last):
  File "/usr/lib/python3.5/tkinter/__init__.py", line 3357, in __del__
    if self.name:
AttributeError: 'Image' object has no attribute 'name'
Traceback (most recent call last):
  File "/home/sunbear/Coding/python35/tkinter/stackoverflow_questions/test52.py", line 22, in <module>
    Logo = Image(file="Logo-S.gif")
TypeError: __init__() missing 1 required positional argument: 'imgtype'

There is a typo in your command in line 22(your original code before edit). You need the following correction to overcome this error, i.e.:

#Logo
#Logo = Image(file="Logo-S.gif")
Logo = PhotoImage(file="Logo-S.gif") #you should change to this.

You can read more about when to use PhotoImage and Image using this link I gave you.

Sun Bear
  • 7,594
  • 11
  • 56
  • 102
  • Thank you for the response, the code now works in IDLE but still no luck launching it without going through IDLE. – L31 Mar 26 '18 at 04:28
  • In my linux terminal, after typing `$ python3 kinematics.py`, your GUI will appear. What happens when you do the same? What error msg are you getting? I had named your script `kinematics.py`. You have to execute this command in the same directory as your script. – Sun Bear Mar 26 '18 at 04:34
  • I'm currently running Windows 10 this is what happens. '$' is not recognized as an internal or external command, operable program or batch file. – L31 Mar 26 '18 at 04:40
  • In linux, `$` refers to the command prompt. At your end, just type `python3 kinematics.py`. Any error? – Sun Bear Mar 26 '18 at 04:46
  • 'python3' is not recognized as an internal or external command, operable program or batch file. – L31 Mar 26 '18 at 04:48
  • Try answer for this question on [Python 2 and Python 3 - Running in Command Prompt](https://stackoverflow.com/a/38734522/5722359). Hope this helps. – Sun Bear Mar 26 '18 at 04:51
  • See also official python [explanation](https://docs.python.org/3.3/using/windows.html) – Sun Bear Mar 26 '18 at 04:58
  • 1
    Great. In short, your situation was caused by 2 issues. One pertains to tkinter command error and the other to the setup of python on windows. Kindly accept this answer by clicking on the "tick" mark. Thanks. – Sun Bear Mar 26 '18 at 07:18
0

I just attempted to run the program with a random gif I found online, all seemed to work to plan. I'm running windows 10 pro... maybe try re-saving/downloading the gif.

enter image description here

Jake
  • 45
  • 2
  • 9