A
A
Ansystef2021-06-07 14:27:54
Python
Ansystef, 2021-06-07 14:27:54

After converting python code to exe, an error occurs, how can I solve this?

60be025e0ba17625944341.png
Code itself:

#-*- coding: utf-8 -*-
from Tkinter import *
def loading():
global file_data
load=open('data_file.txt','r')
file_data=load.readlines()
list=file_data
Andrey=list[0]
label2.config(text=str(Andrey)+' Earned '+str(name2),bg='yellow')
Lisa=list[1]
label1.config(text=str(Lisa ) + ' Earned ' + str(name1), bg='cyan')
Julia=list[2]
label3.config(text=str(Julia) + ' Earned ' + str(name3), bg ='green')
def data():
global Andrey,Lisa,Julia,file_data
save=open('data_file.txt','w')
save.write(str(Andrey)+'\n')
save.writelines(str(Lisa)+"\n")
save.writelines(str(Julia)+"\n")
save.close()
def change_accept():
Andrey=val1.get()
Lisa=val2.get ()
Julia=val3.get()
def Value():
global val1, val2, val3
value=Tk()
label_ch1=Label(value,text='Andrey')
val1=Entry(value)
label_ch2=Label(value,text ='Lisa')
val2=Entry(value)
label_ch3=Label(value,text='Julia')
val3=Entry(value)
btn_accept=Button(value,text='Accept',command=change_accept)
label_ch1.pack()
val1.pack()
label_ch2.pack()
val2.pack()
label_ch3.pack()
val3.pack()
btn_accept.pack()
value.title('New Value')
value.geometry('150x140')
value.mainloop()
def J150():
global Julia
Julia=Julia+150
label3 .config(text=str(Julia) + ' Earned ' + str(name3),bg='green')
def A150():
global Andrey
Andrey=Andrey+150
label2.config(text=str(Andrey) +' Earned '+str(name2),bg='yellow')
def L150():
global Lisa
Lisa=Lisa+150
label1.config(text=str(Lisa) + ' Earned ' + str (name1),bg='cyan')
global Andrey,Lisa,Julia,Val_Change1,Val_Change2,name1,name2,name3,val1,val2,val3
name1='Lisa'
name2='Andrey'
name3='Julia'
Andrey=int()
Lisa=int()
Julia=int()
win=Tk()
Version='PreAlpha 0.1'
version_label=Label(text=Version). place(x=490,y=190)
label1=Label(text=str(Lisa)+' Earned '+str(name1))
label2=Label(text=str(Andrey)+' Earned ' +str(name2))
label3=Label(text=str(Julia)+' Earned '+str(name3))
btn1=Button(text='Lisa +150',command=L150,bg='cyan' ,activebackground='cyan',width=20)
btn2=Button(text='Andrey +150',command=A150,bg='yellow',activebackground='yellow',width=20)
btn3=Button(text=' Julia +150',command=J150,bg='green',activebackground='green',width=20)
btn_data=Button(text='Save',command=data)
btn_load=Button(text='Load',command=loading)
label1.pack()
label2.pack()
label3.pack()
btn1.pack()
btn2.pack()
btn3.pack()
btn_data.pack()
btn_load .pack()
win.geometry('500x200')
win.iconbitmap('icon.ico')
win.title('Walking the dog')
win.resizable(False,False)
win.mainloop()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kotar4ik, 2021-06-07
@Kotar4ik

I'm not sure exactly, but I think the problem may be in the file used:
load=open('data_file.txt','r')
Is it in the same folder as the .exe?
PS It's better not to assign variables as global ones.
return file_data
And then assigning the resulting value to a variable:
new_value = loading()
Much better

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question