I have created a mini app that is used for combining a bunch of excel files, but I cant execute the exe due to this error. What I find strange is that I am not even using Numpy in my script. I have installed and reinstalled numpy, but that did not fix the issue.
I created a virtual environment which has the following libraries installed.
Error on Executing exe
Here is my code:
import tkinter as tk
from tkinter.simpledialog import askstring, askinteger
from tkinter.messagebox import showerror
from tkinter import messagebox
from tkinter import filedialog
from tkinter import ttk
import os
from os import path
import pandas as pd
import fnmatch
import glob
import datetime
from datetime import datetime
import time
import calendar
class Splash(tk.Toplevel):
def __init__(self, parent, width=0.8, height=0.6, useFactor=True):
tk.Toplevel.__init__(self, parent)
self.title("Splash")
w = 300
h = 200
x = 50
y = 100
self.geometry('%dx%d+%d+%d' % (w, h, x, y))
lbl = tk.Label(self,text="Combine Excel\n Version 1.0", bg = 'lightgrey' )
lbl.place(x=25, y=30)
self.master.overrideredirect(True)
self.lift()
## required to make window show before the program gets to the mainloop
self.update()
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.withdraw()
splash = Splash(self)
## simulate a delay while loading
time.sleep(1)
## finished loading so destroy splash
splash.destroy()
def getfiles():
listbox.delete(0,tk.END)
beginput = entry_1.get()
endinput = entry_2.get()
timefmt = "%m/%d/%y"
start = calendar.timegm(datetime.strptime(beginput, timefmt).timetuple())
end = calendar.timegm(datetime.strptime(endinput, timefmt).timetuple())
year = datetime.strptime(beginput, timefmt).strftime('%Y')
monthyr = datetime.strptime(beginput, timefmt).strftime('%m-%y') + ' Daily Collection'
yearmm = 'CA_LoanLvl_' + time.strftime("%Y%m%d")
yrnmsum = 'CA_Sum_' + time.strftime("%Y%m%d")
frame = pd.DataFrame()
list_ = []
cols = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,37,39,40,41,43,44,45,46,47,49,50,51,52,53,54,55,56,57]
path1 = path.join(r'\\corp.int\cms\DeptData\Monthly Reporting'
'\Daily Collection',year,monthyr,'Data')
pathexpt = path.join(r'\\corp.int\cms\DeptData\XX\DS\DataDownloads\Combine',yearmm)
pathexptsum = path.join(r'\\corp.int\cms\DeptData\XX\DS\DataDownloads\Combine',yrnmsum)
mypath = path1
def test(f):
if (not os.path.isfile(f)):
return 0
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(f)
return start<=ctime and end>=ctime
files = [f for f in glob.glob(os.path.join(mypath, "adv*")) if test(f)]
for item in files:
listbox.insert(tk.END, os.path.basename(item))
if __name__ == "__main__":
App()
# Create the main window
root = tk.Tk()
s = ttk.Style(root)
s.theme_use('clam')
root.title("Combine GNMA Files")
# set the root window's height, width and x,y position
# x and y are the coordinates of the upper left corner
w = 600
h = 400
x = 50
y = 100
# use width x height + x_offset + y_offset (no spaces!)
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
# use a colorful frame
frame = tk.Frame(root, bg='darkblue')
frame.pack(fill='both', expand='yes')
label = tk.Label(frame, text="Start Date-mm/dd/yy", bg = 'lightblue')
label.place(x=20, y=30)
label2 = tk.Label(frame, text="End Date-mm/dd/yy", bg = 'lightblue')
label2.place(x=20, y=100)
entry_1 = tk.Entry(root)
entry_1.place(x=20,y=60)
entry_2 = tk.Entry(root)
entry_2.place(x=20,y=130)
btn_1 = tk.Button(root,text="Get Files", bg='light grey', command = getfiles)
btn_1.place(x=400, y=15)
listbox = tk.Listbox(root)
listbox.place(x=20, y=160, width = 400)
def on_closing():
if messagebox.askokcancel("Quit", "Do you want to quit?"):
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()
If anyone runs across this, it seems it has to do with the version of Numpy that is causing errors with Pyinstaller. Take a look at the link below.
[How to fix 'Missing required dependencies ['numpy']' when running packaged app made with PyInstaller?
Related
these two scripts worked fine seperatly and after many differant approches i have got the page1 to open menu_func however when i close menu_func the window remains but deletes the photos etc?
i want the back command to return to the page1 script
i also get this error,
invalid command name "36335088time_now"
while executing
"36335088time_now"
("after" script)
not related to my actual problem but if anybody knows how to get rid of it help would be appreciated
1.page1 code
import tkinter as tk
from tkinter import *
from PIL import Image, ImageTk
from time import strftime
import subprocess
import menu_func
page1 = tk.Toplevel()
width_value=page1.winfo_screenwidth()
height_value=page1.winfo_screenheight()
page1.geometry('%dx%d-0+0' % (width_value, height_value))
page1.resizable(False, False)
BG1_img = Image.open('BG-BLK-1.png')
BG2_img = BG1_img.resize((width_value,height_value))
BG3_img = ImageTk.PhotoImage(BG2_img)
canvas = Canvas(page1)
canvas.pack(expand=True, fill=tk.BOTH)
limg = Label(canvas, i=BG3_img)
limg.pack()
SD1_img = Image.open('Bshut.png')
SD2_img = ImageTk.PhotoImage(SD1_img)
MU1_img = Image.open('./LIST.png')
MU2_img = ImageTk.PhotoImage(MU1_img)
def close():
page1.destroy()
#def MU_COMM():
# import menu_func.py
# page1.exit()
# exec(open('menu_func.py').read())
def time_now():
T_D = strftime('%A, %d %h %Y %H:%M:%S')
show_date.config(text = T_D)
show_date.after(1000, time_now)
exit_button = Button(canvas,image=SD2_img,
command=close,borderwidth='0',border='0',bg='#000000', highlightthickness='0')
exit_button.place(x=1700, y=900)
show_date = Label(canvas, font="Calibri, 46", fg="red", border='0',bg='#00090e')
show_date.place(x=440, y=960)
menu_button = Button(canvas, image=MU2_img, command= menu_func.menu, borderwidth=0,
bg='#000000', highlightthickness=0)
menu_button.place(x=50, y=900)
time_now()
page1.wm_attributes('-fullscreen', 'True')
page1.mainloop()
2.menu_func code
import tkinter as tk
from tkinter import *
from tkinter.messagebox import showinfo
from PIL import Image, ImageTk
from time import strftime
def menu():
pageM = tk.Toplevel()
w_v=pageM.winfo_screenwidth()
h_v=pageM.winfo_screenheight()
pageM.geometry('%dx%d-0+0' % (w_v, h_v))
pageM.resizable(False, False)
BG1m_img = Image.open('BG-BLK-1.png')
BG2m_img = BG1m_img.resize((w_v,h_v))
BG3m_img = ImageTk.PhotoImage(BG2m_img)
canvas = Canvas(pageM)
butt_W = int(w_v/28)
butt_H = int(h_v/31)
img_W = int(w_v/8)
img_H = int(h_v/4)
canvas = Canvas(pageM)
canvas.pack(expand=True, fill=tk.BOTH)
limg = Label(canvas, i=BG3m_img)
limg.pack()
def time_now():
T_D = strftime('%H:%M:%S')
show_time.config(text = T_D)
show_time.after(1000, time_now)
show_time = Label(canvas, font="Calibri, 46", fg="red", border='0',bg='#003a52')
show_time.place(x=int(w_v/2.3), y=int(h_v/50))
def call_COM():
showinfo(title='Information',message='phone Button clicked!')
call_img = Image.open('CALL.png')
cal1_img = call_img.resize((img_W,img_H))
cal2_img = ImageTk.PhotoImage(cal1_img)
button1=tk.Button(canvas, image=(cal2_img),borderwidth=0,bg='#000000', highlightthickness=0)
button1.place(x=int(w_v/5*1-(img_W)+50),y=int(h_v/3*0.8-(img_H/2)))
def map_COM():
exec(open("mapscreen.py").read())
c1_img = Image.open('comp.png')
c2_img = c1_img.resize((img_W,img_H))
c3_img = ImageTk.PhotoImage(c2_img)
button2=tk.Button(canvas, image=c3_img,command=map_COM,borderwidth=0,bg='#000000', highlightthickness=0)
button2.place(x=int(w_v/5*2-(img_W/1.2)+50),y=int(h_v/3*0.8-(img_H/2)))
def user_COM():
showinfo(title='Information',message='user Button clicked!')
u1_img = Image.open('user.png')
u2_img = u1_img.resize((img_W,img_H))
u3_img = ImageTk.PhotoImage(u2_img)
button3=tk.Button(canvas, image=u3_img,borderwidth=0,bg='#000000', highlightthickness=0)
button3.place(x=int(w_v/5*3-(img_W/1.5)+50),y=int(h_v/3*0.8-(img_H/2)))
def set_COM():
showinfo(title='Information',message='settings Button clicked!')
s1_img = Image.open('settings.png')
s2_img = s1_img.resize((img_W,img_H))
s3_img = ImageTk.PhotoImage(s2_img)
button4=tk.Button(canvas, image=s3_img,borderwidth=0,bg='#000000', highlightthickness=0)
button4.place(x=int(w_v/5*4-(img_W/2)+50),y=int(h_v/3*0.8-(img_H/2)))
def bro_COM():
exec(open('browser.py').read())
b1_img = Image.open('brows.png')
b2_img = b1_img.resize((img_W,img_H))
b3_img = ImageTk.PhotoImage(b2_img)
button5=tk.Button(canvas, image=b3_img,command=bro_COM,borderwidth=0,bg='#000000', highlightthickness=0)
button5.place(x=int(w_v/5*1-(img_W)+50),y=int(h_v/3*2.2-(img_H/1.5)))
def mus_COM():
showinfo(title='Information',message='Music Button clicked!')
m1_img = Image.open('music.png')
m2_img = m1_img.resize((img_W,img_H))
m3_img = ImageTk.PhotoImage(m2_img)
button6=tk.Button(canvas, image=m3_img,borderwidth=0,bg='#000000', highlightthickness=0)
button6.place(x=int(w_v/5*2-(img_W/1.2)+50),y=int(h_v/3*2.2-(img_H/1.5)))
def lite_COMM():
showinfo(title='Information',message='hardware Button clicked!')
t1_img = Image.open('Torch.png')
t2_img = t1_img.resize((img_W,img_H))
t3_img = ImageTk.PhotoImage(t2_img)
button7=tk.Button(canvas, image=t3_img,borderwidth=0,bg='#000000', highlightthickness=0)
button7.place(x=int(w_v/5*3-(img_W/1.5)+50),y=int(h_v/3*2.2-(img_H/1.5)))
def back_COM():
pageM.quit()
# exec(open('start_screen.py').read())
SD1_img = Image.open('home.png')
SD2_img = SD1_img.resize((img_W,img_H))
SD3_img = ImageTk.PhotoImage(SD2_img)
button8=tk.Button(canvas, image=SD3_img,command=back_COM,borderwidth=0,bg='#000000', highlightthickness=0)
button8.place(x=int(w_v/5*4-(img_W/2)+50),y=int(h_v/3*2.2-(img_H/1.5)))
time_now()
print(w_v/5*4-(img_W/2))
print(w_v/5*1-(img_W))
print(img_W)
print(h_v)
print(w_v)
pageM.mainloop()
the print(variables) arnt really part of the script there just there to help me work out locations of widgets!
i also understand this is a long code, if anybody know a way to make it shorter or more efficient please let me know, im not a programmer
thanks
Good day folks,
I created a simple GUI that let's the user browse through their files with tkinter's filedialog.
After picking one, python reads the data from the (excel) file, and with that creates a new .txt file.
Now after doing that, I would like python to make that .txt file pop up, so that the user gets to see the result.
How do I do this?
Edit for the bot-moderator- he wanted code examples:
File1.py
from contextlib import nullcontext
import File2 as tp
import tkinter as tk
from tkinter import StringVar, messagebox
from tkinter import filedialog
filename = None
def pickFile():
global filename
filename = filedialog.askopenfilename()
#Creating main window
master = tk.Tk()
masterWidth = 350
masterHeight = 250
master.iconbitmap('C:\...')#directory
master.title('Title')
# get the screen dimension
screen_width = master.winfo_screenwidth()
screen_height = master.winfo_screenheight()
# find the center point
center_x = int(screen_width/2 - masterWidth / 2)
center_y = int(screen_height/2 - masterHeight / 2)-100
# set the position of the window to the center of the screen
master.geometry(f'{masterWidth}x{masterHeight}+{center_x}+{center_y}')
#Creating startbutton
startButton = tk.Button (master, text="Start", height=1, width=3, command=lambda: tp.readFile(filename))
#Creating bladerknop
browseButton = tk.Button (master, text='browse...', command=pickFile)
browseLabel = tk.Label(master, text='Choose a file')
startButton.place(x=175,y=200)
browseButton.place(x=210,y=50)
browseLabel.place (x=110,y=52)
master.mainloop()
File2.py
import pandas as pd
import tkinter as tk
from tkinter import messagebox
#declaring variables for later use
data = None
def missingValues(path):
if path is not None:
data = pd.read_excel(path, header=None)
return data
else:
messagebox.showinfo('No file chosen', 'Choose a file first.')
def readFile(path):
data = missingValues(path)
with open("C:\...\newFile.txt", 'w') as newTxt:
count = 0
for index, row in data.iterrows():
code = data.loc[count,0]
price = toEightBits(data.loc[count,1])
newTxt.write(str(code))
newTxt.write(str(price))
newTxt.write("\n")
count += 1
newTxt.close()
I have made a simple GUI that has two buttons for a Square function and Exit button. I want to print the results on the canvas as shown in the expected results.
Here are my codes
from tkinter import *
from PIL import Image,ImageTk
from tkinter import filedialog
from PIL import Image, ImageTk
import os
import cv2
import numpy as np
import time
class application(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent = parent
self.minsize(width=300,height=500)
self.initialize()
def initialize(self):
self.grid_columnconfigure(0,weight=1)
self.grid_columnconfigure(1,weight=1)
self.grid_columnconfigure(2,weight=1)
#Button widgets
###########################################################################################
self.button1 = Button(self,text='Square',bg= 'blue',width=15,height=2, command =Square)
self.button1.grid(column=0,row=1,sticky='W',pady=5)
self.button3 = Button(self,text='Exit',bg= 'blue',width=10,height=2,command=self.destroy)
self.button3.grid(column=1,row=5,sticky='W',pady=5)
#Text widget for inserting the result
############################################################################################
self.canvas = Canvas(self,width=230,height=180,state=NORMAL)
self.canvas.grid(column=0,row=4,sticky='W',padx=100,pady=10)
#self.canvas.configure(bg='green')
#Label widget
############################################################################################
self.label3 = Label(self,text="Square",bg = 'red',width=10,height=2,anchor="center")
self.label3.grid(column=0,row=3,sticky='W',padx=120)
def Square(self):
for i in range(1,10):
y = i**2
print(i, y)
if __name__ == "__main__":
app = application(None)
#font.nametofont('TkDefaultFont').configure(size=10)
app['bg']='red'
app.title("square")
app.mainloop()
My expected results are given in the image below
Not entirely sure what you are asking. But, if you just want to create text on canvas use canvas.create_text(x, y, text).
from tkinter import *
from PIL import Image,ImageTk
class application(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent = parent
self.minsize(width=300,height=500)
self.initialize()
def initialize(self):
self.grid_columnconfigure(0,weight=1)
self.grid_columnconfigure(1,weight=1)
self.grid_columnconfigure(2,weight=1)
#Button widgets
###########################################################################################
self.button1 = Button(self,text='Square',bg= 'blue',width=15,height=2, command=self.Square)
self.button1.grid(column=0,row=1,sticky='W',pady=5)
self.button3 = Button(self,text='Exit',bg= 'blue',width=10,height=2,command=self.destroy)
self.button3.grid(column=1,row=5,sticky='W',pady=5)
#Text widget for inserting the result
############################################################################################
self.canvas = Canvas(self,width=230,height=180,state=NORMAL)
self.canvas.grid(column=0,row=4,sticky='W',padx=100,pady=10)
#self.canvas.configure(bg='green')
self.label3 = Label(self,text="Square",bg = 'red',width=10,height=2,anchor="center")
self.label3.grid(column=0,row=3,sticky='W',padx=120)
def Square(self):
for i in range(1,10):
y = i**2
print(i, y)
c_id = self.canvas.create_text(0, 20, text=f"{i}\t{y}", fill="blue", font="Times 14")
bbox = self.canvas.bbox(c_id)
self.canvas.coords(c_id, 100, bbox[3]*i)
if __name__ == "__main__":
app = application(None)
#font.nametofont('TkDefaultFont').configure(size=10)
app['bg']='red'
app.title("square")
app.mainloop()
When I run the .py file, the program runs fine as in self.error updates as robocopy is running. However after I've changed it to a .exe file using pyinstaller -F -w Shortcutsv2.1.py I've noticed that the tkinter label which shows how many files it has updated (self.error) doesn't update until after the terminal is closed. Is there a way to have it work like the script? I'm assuming this is due to a setting in pyinstaller but I may be wrong
CODE:
from subprocess import PIPE, run
import tkinter as tk
from tkinter import ttk
import tkinter.messagebox as mb
import tkinter.font as tkFont
from os import path
from os import listdir
from os import mkdir
from os import walk
from glob import glob
import threading
import pandas as pd
from datetime import datetime
class Windows(threading.Thread):
def __init__(self, master):
threading.Thread.__init__(self)
self.width = 400
self.height = 150
master.geometry(f"{self.width}x{self.height}")
master.title("Shortcuts")
#master.iconbitmap(r'ip.ico')
self.frame = tk.Frame(master,bg="white")
self.frame.place(relx=0, rely=0, relwidth=1, relheight=1)
self.font = ('Helvetica', '10')
#Source path label and text entry
self.srcLabel = tk.Label(self.frame, text="Source Path:", font=self.font, bg="white")
self.srcLabel.place(relx=0.001, rely=0.026, relwidth=0.31, relheight=0.2)
self.srcEntry = tk.Entry(self.frame, font=self.font, bg="white")
self.srcEntry.place(relx=0.31, rely=0.026, relwidth=0.68, relheight=0.2)
#Destination path label and text entry
self.dstLabel = tk.Label(self.frame, text="Destination Path:", font=self.font, bg="white")
self.dstLabel.place(relx=0.001, rely=0.246, relwidth=0.31, relheight=0.2)
self.dstEntry = tk.Entry(self.frame, font=self.font, bg="white")
self.dstEntry.place(relx=0.31, rely=0.246, relwidth=0.68, relheight=0.2)
#New Folder to be created label and text entry
self.nfLabel = tk.Label(self.frame, text="New Folder:", font=self.font, bg="white")
self.nfLabel.place(relx=0.001, rely=0.466, relwidth=0.31, relheight=0.2)
self.nfEntry = tk.Entry(self.frame, font=self.font, bg="white")
self.nfEntry.place(relx=0.31, rely=0.466, relwidth=0.68, relheight=0.2)
#Submit
self.submit = tk.Button(self.frame, text="Submit", bg="white", font=self.font,
command = self.threadCmd)
self.submit.place(relx=0.5, rely=0.733, relwidth=0.3, relheight=0.2)
#Errors
self.error = tk.Label(self.frame, text="", font=self.font, bg="white", fg="red")
self.error.place(relx=0.001, rely=0.733, relwidth=0.53, relheight=0.2)
def findFile(self, dirPath):
#finds the full path of all files including within the subdirectories
i = 0
temp = []
filesInDir = [f"{dirPath}\\{a}" for a in listdir(dirPath)]
for a in filesInDir:
i += 1
fullPath = path.join(dirPath, a)
if path.isdir(fullPath):
temp = temp + self.findFile(fullPath)
else:
temp.append(fullPath)
return temp
def lowestFolder(self, direc):
#finds the lowest last folder if any and creates the ~~~~.txt in there to ensure it is the last file to be copied
subdir = [x[0] for x in walk(direc)]
subdir.sort()
if subdir[-1] == direc:
f = open(path.join(direc,"~~~~.txt"),"w+")
f.close()
else:
self.lowestFolder(str(path.join(direc,subdir[-1])))
def Run(self):
if not path.exists(self.srcEntry.get()):
self.error.config(text="Can't find src path", fg="red")
elif not path.exists(self.dstEntry.get()):
self.error.config(text="Can't find dstn path", fg="red")
else:
dest = self.dstEntry.get() + "\\" + self.nfEntry.get()
if path.isdir(dest):
self.error.config(text="Folder Exists", fg="red")
else:
self.error.config(text="")
self.filename = "logs.xlsx"
self.listOfFiles = glob(path.join(".",self.filename))
self.lowestFolder(self.srcEntry.get())
filesTransferred = self.findFile(self.srcEntry.get())
length = len(filesTransferred)
mkdir(dest)
date = datetime.now()
run(f"start cmd /K RoboCopy.exe \"{self.srcEntry.get()}\" \"{dest}\" *.* /E /Z", stdout=PIPE, stdin=PIPE, stderr=PIPE, shell=True)
#Checks if all files have been transferred before moving on
i = 0
while(i < length):
fullPath = filesTransferred[i].replace(self.srcEntry.get(), dest)
if path.exists(fullPath):
i += 1
self.error.config(text=f'Transferring file(s): {i}/{length}', fg='black')
temp2 = self.findFile(dest)
temp2 = [x.replace(dest, "..") for x in temp2]
if length == len(temp2):
#Creates log file if not created
if not self.listOfFiles:
writer = pd.ExcelWriter(self.filename, engine='xlsxwriter')
writer.save()
df = pd.read_excel(self.filename)
#creates file if it doesn't exist else apppends
df2 = pd.DataFrame({"Started" : [date],
"Source": [self.srcEntry.get()],
"Destination": [self.dstEntry.get()],
"Files": [", ".join(temp2)]})
df = df.append(df2, sort=False)
df.to_excel(self.filename, index=False)
self.error.config(text="Files copied successfully.", fg="green")
#IF ROBOCOPY FREEZES WHEN YOU CLICK ON IT THEN JUST PRESS TAB AND IT SHOULD RESUME
else:
self.error.config(text="All files were not copied.", fg="red")
def threadCmd(self):
self.result = None
y = threading.Thread(target=self.Run)
y.start()
if __name__ == "__main__":
root = tk.Tk()
x = threading.Thread(target=Windows, args=(root,))
x.start()
x.join
root.mainloop()
EDIT 1
"There are couple problems here. 1. Inherit class Windows(threading.Thread): but don't use this object. 2. Passing a class definition as .Thread(target=Windows. 3. Useless x.join without calling it. 4. Accessing tkinter objects, e.g.self.srcEntry.get(), from a Thread."
I've changed the code to the below so now:
1) Can't make this change as I'm using .start()
2) Changed this to an instance
3) called the function
4) Didn't make this change as wasn't sure what the issue was. Needs more clarification
The issue which I had posted for still persists however I appreciate the help to tidy up my code :)
if __name__ == "__main__":
root = tk.Tk()
x = Windows(root)
x.start()
x.join()
root.mainloop()
I was using subprocess.run instead of subprocess.Popen, subprocess.run waits for the terminal command to complete before moving on with the script. Whereas subprocess.Popen doesn't.
Edit: What I find strange is that when I would run it as a .py file subprocess.run worked the same as subprocess.Popen however when I had used pyinstaller then subprocess.run worked how it's supposed to.
I have constructed a messaging application, but it seems to have incorrect syntax:
from tkinter import messagebox
from AESEncDec import *
from MD5Hashing import *
from RSAEncDec import *
color = 'lightblue' #color our background
class Application(Frame):
def __init__(self, root=None):
Frame.__init__(self, root)
self.frame_width = 700
self.frame_height = 400
# Set configuration our frame
self.config(width = self.frame_width, height = self.frame_height, bg = color)
self.pack()
# Create textBox for input data
self.textbox_one = Text()
self.textbox_one.place(x = 30, y = 170, height = 200, width = 300 )
# Create textBox for result
self.textbox_two = Text()
self.textbox_two.place(x = 370, y = 170, height = 200, width = 300 )
label_input_text = Label( text = "Input text: ", bg = color)
label_input_text.place(x = 30, y = 155, height = 10, width = 70 )
During execution I get the following error:
Traceback (most recent call last):
File "/home/artur/Documents/MScProject/MSc Project/Task #179276/main_program.py", line 11, in
class Application(Frame):
NameError: name 'Frame' is not defined
What might be the problem?
Frame is a class from the tkinter module.
To fix:
from tkinter import Frame
See an example in the official documentation: https://docs.python.org/3.7/library/tkinter.html#a-simple-hello-world-program
You also need to import Text and Label:
from tkinter import Frame
from tkinter import Text
from tkinter import Label
Or:
from tkinter import *
Here is how you can fix your code (I removed the unused imports):
import tkinter
color = 'lightblue' # color our background
class Application(tkinter.Frame):
def __init__(self, root=None):
super(Application, self).__init__(root)
self.frame_width = 700
self.frame_height = 400
# Set configuration our frame
self.config(width=self.frame_width, height=self.frame_height, bg=color)
self.pack()
# Create textBox for input data
self.textbox_one = tkinter.Text()
self.textbox_one.place(x=30, y=170, height=200, width=300)
# Create textBox for result
self.textbox_two = tkinter.Text()
self.textbox_two.place(x=370, y=170, height=200, width=300)
label_input_text = tkinter.Label(text="Input text: ", bg=color)
label_input_text.place(x=30, y=155, height=10, width=70)
root = tkinter.Tk()
app = Application(root)
app.mainloop()