简体   繁体   中英

Tkinter doesn't work with .py to .exe conversions

I have been working on a Python script which requires me to make a window for it and process the data entered by the user in text boxes and with button interaction. For this I decided to use Tkinter...

I have had no problems at all so far, and limited my programming so far so I wouldn't use modules not included in the 2.7 python library, because I anticipated those would be a problem when trying to compile Python code into an executable file.

Turns out my issues were actually with a module included in the Python library: Tkinter.

I have tried both py2exe and pyinstaller , and both gave me the same kind of mistakes:

Import errors, "no such module as Tkinter".

I have tried everything I could come up with: I have used --onefile , I have added hidden imports on the .spec file and then used pyinstaller on it... All of these tries produced slightly different errors, but all of them revolved around not being able to import Tkinter.

I would be really thankful if someone has had a similar experience with pyinstaller or py2exe . I know there are similar topics to this one on the forum but I tried everything suggested that would apply to me on those other topics but I couldn't sort this problem out.

My complete tkinter code is:

import Tkinter 
from Tkinter import * 

master = Tk() 
master.title('App') 
canvas = Canvas(master, width = 666, height = 400) 
canvas.pack() 
imagem = PhotoImage(file='C:\\ProjetoFCTUNL\\a0VRm.gif') 
canvas.create_image(0, 0, anchor = NW, image= imagem) 

def callback(): 
    global livro 
    livro = e1.get() +'.txt' 

def callback2(): 
    global livro2 
    livro2 =e2.get() +'.txt' 
    global livro 
    livro = e1.get() +'.txt' 

v = StringVar() 
v2 = StringVar() 
e1 = Entry(master, textvariable=v) 
e1.pack() 
e2 = Entry(master, textvariable=v2) 
e2.pack() 

The error I usually get is a window saying "failed to execute script" and if I open it via CMD it just says "failed to import tkinter"

有时对我来说,基于不同的 python 版本,它只是“导入 tkinter”而不是“导入 Tkinter”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM