run a function from a button in a frame - python-3.x

I'm just starting with python 3, I've made 3 scripts which do what I want them to do and now I'm trying to include them in a very basic GUI that I made with tinker.
I've joined my 3 scripts into a single file and made a function of each of them
Basically I'd like to run this or that function when I click on a button in the frame.
The problem is that of course I d'ont know how to do it, can someone point me in the right direction ?
Thanks for the help.
from tkinter import *
from datetime import *
import time
def c60duree(delta):
(h, r) = divmod(delta.seconds, 3600)
(m, s) = divmod(r, 60)
return "%s%02d:%02d:%02d" % (
"%d jour(s) " % delta.days if delta.days > 0 else "",
h,
m,
s,
)
def code60():
saisie=0
c60=[[],[]]
while saisie != "X":
c60d=datetime.now()
print ("Code 60 activé à ", c60d.strftime("%H:%M:%S"))
saisie=input("Tapez entree pour la fin du code 60, X pour sortir : ")
c60f=datetime.now()
print("Debut ", c60d.strftime("%H:%M:%S"))
print("Fin ", c60f.strftime("%H:%M:%S"))
c60x=c60f-c60d
print("Duree ", c60duree(c60x))
print("-------------")
c60[0].append(c60d)
c60[1].append(c60f)
#del(c60[0],[-1])
#del(c60[1],[-1])
#return
def relais():
rel=[[],[],[],[],[]]
print("Relais pilote demarré ")
relh=datetime.now()
relv=input("Quelle voiture ? ")
relp=input("Quel pilote repart ? ")
rele=input("Quantité d'essence ? ")
input("Tapez entrée à la sortie des stands ")
rels=datetime.now()
rel[0].append(relh), rel[1].append(relv), rel[2].append(relp), rel[3].append(rele), rel[4].append(rels)
print("Dureé ", rels-relh)
print(*rel)
def essence():
ess=[[],[],[],[]]
print("Ravitaillement essence demarré ")
essh=datetime.now()
essv=input("Quelle voiture ? ")
essp=input("Quel pilote ? ")
essq=input("Combien de litres ? ")
ess[0].append(essh), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq)
print(*ess)
fenetre = Tk()
fenetre['bg']='grey'
# frame 1
Frame1 = Frame(fenetre, bg="yellow", borderwidth=1, relief=GROOVE)
Frame1.pack(side=LEFT, padx=5, pady=5)
# frame 2
Frame2 = Frame(fenetre, bg="green", borderwidth=1, relief=GROOVE)
Frame2.pack(side=LEFT, padx=5, pady=5)
# frame 3
Frame3 = Frame(fenetre, bg="red", borderwidth=1, relief=GROOVE)
Frame3.pack(side=LEFT, padx=5, pady=5)
# Ajout de labels
Label(Frame1, text="Essence").pack(padx=300, pady=100)
Label(Frame2, text="Relais").pack(padx=300, pady=100)
Label(Frame3, text="C60").pack(padx=300, pady=100)

If you want to continue using Labels, you can bind a function to them like this:
# Ajout de labels
label1 = Label(Frame1, text="Essence")
label1.bind("<Button-1>", lambda event: essence())
label1.pack(padx=300, pady=100)
label2 = Label(Frame2, text="Relais")
label2.bind("<Button-1>", lambda event: relais())
label2.pack(padx=300, pady=100)
label3 = Label(Frame3, text="C60")
label3.bind("<Button-1>", lambda event: code60())
label3.pack(padx=300, pady=100)
I've had to give the labels each a name so I could add the binding. The bind method takes a key and a function. The key I've given is Button-1, which is the left mouse button. Therefore when you click on the label the function is run. When you bind a function, and extra argument called event is added. For this example we don't need event, so I've used lambda event: to essentially ignore it and call the function like normal.
Another way you could do this is with buttons:
# Ajout de labels
Button(Frame1, text="Essence", command = essence).pack(padx=300, pady=100)
Button(Frame2, text="Relais", command = relais).pack(padx=300, pady=100)
Button(Frame3, text="C60", command = code60).pack(padx=300, pady=100)
This is a lot more straightforward but looks different to a Label.
EDIT
To make the text appear in the GUI, you could do something like this:
def essenceResult(ess, ent1, ent2, ent3):
essh=datetime.now()
essv = ent1.get()
essp = ent2.get()
essq = ent3.get()
ess[0].append(essh), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq)
resultLabel = Label(Frame4, text = str(ess))
resultLabel.grid(row = 5, column = 0, columnspan = 2)
def essence():
print("yr")
Frame4.grid(row = 1, column = 0)
ess=[[],[],[],[]]
Label1 = Label(Frame4, text = "Ravitaillement essence demarré ")
Label1.grid(row = 0, column = 0, columnspan = 2)
essvLabel = Label(Frame4, text = "Quelle voiture ? ")
essvEntry = Entry(Frame4)
essvLabel.grid(row = 1, column = 0)
essvEntry.grid(row = 1, column = 1)
esspLabel = Label(Frame4, text = "Quel pilote ? ")
esspEntry = Entry(Frame4)
esspLabel.grid(row = 2, column = 0)
esspEntry.grid(row = 2, column = 1)
essqLabel = Label(Frame4, text = "Combien de litres ? ")
essqEntry = Entry(Frame4)
essqLabel.grid(row = 3, column = 0)
essqEntry.grid(row = 3, column = 1)
submitButton = Button(Frame4, text = "Submit", command = lambda: essenceResult(ess, essvEntry, esspEntry, essqEntry))
submitButton.grid(row = 4, column = 0, columnspan = 2)
fenetre = Tk()
fenetre['bg']='grey'
# frame 1
Frame1 = Frame(fenetre, bg="yellow", borderwidth=1, relief=GROOVE)
Frame1.grid(row = 0, column = 0, padx=5, pady=5)
# frame 2
Frame2 = Frame(fenetre, bg="green", borderwidth=1, relief=GROOVE)
Frame2.grid(row = 0, column = 1, padx=5, pady=5)
# frame 3
Frame3 = Frame(fenetre, bg="red", borderwidth=1, relief=GROOVE)
Frame3.grid(row = 0, column = 2, padx=5, pady=5)
Frame4 = Frame(fenetre)
Frame4 is used to show the things for essence, but is not displayed until the user presses the button. The inputs have been replaced with a label for the question and an entry for the user to put their answer. Then when they press submit, the essenceResult function adds a label with what the print function used to show.

Related

Getting a list variable out of Tkinter window

I am trying to get a list out of Tkinter and I want to add a Y-axis scroll bar to the list box but don't know-how. My code is as follows:
window = Tk()
window.title('Select Multiple Industries')
window.geometry('400x800')
def showindowelected():
industries = []
iname = lb.curselection()
for i in iname:
op = lb.get(i)
industries.append(op)
print (industries)
window.destroy()
#for val in industries:
#print(val)
show = Label(window, text = "Select Multiple Industries", font = ("Times", 14), padx = 10, pady = 10)
show.pack()
lb = Listbox(window, selectmode = "multiple")
lb.pack(padx = 10, pady = 10, expand = YES, fill = "both")
x = ["Brewing","Papermills","Cheese Manufacturing","Steel Mill", "Salt Making"]
for item in range(len(x)):
lb.insert(END, x[item])
lb.itemconfig(item, bg = "whitesmoke" if item % 2 == 0 else "silver")
Button(window, text=" Select > ", command=showindowelected, bg='green', fg='white').pack()
window.mainloop()
Once the window is destroyed, I want the selected variables stored in a list.

Run function in form (ctd)

Here's my current code and the changes I've made so far from the previous version
I've reset the variables at the start because I did not want them to be reset each time the function was executed
I've added a ess_e variable for the entry of the procedure, I want this variable to store the localtime when the function is executed
I've added a ess_s variable for the exit of the procedure after all the infos are entered which should be localtime when the submit button (changed text) is pushed
The remaining problems are
root.bind does not work, I've tried several alternatives with fenetre as you suggested but I could not make it work.
I get an error when I run the 2nd function (essenceresult)
File "D:\Bureautique\Python\Scripts\interface-test.py", line 57, in essenceResult
ess_e = ent0.get()
AttributeError: 'datetime.datetime' object has no attribute 'get'
I still have to make the frame to display the previous results but I'll get there in due time :)
Thanks a lot for the help
from tkinter import *
from datetime import *
import time
ess=[[],[],[],[],[]]
rel=[[],[],[],[],[]]
c60=[[],[]]
def c60duree(delta):
(h, r) = divmod(delta.seconds, 3600)
(m, s) = divmod(r, 60)
return "%s%02d:%02d:%02d" % (
"%d jour(s) " % delta.days if delta.days > 0 else "",
h,
m,
s,
)
def code60():
saisie=0
while saisie != "X":
c60d=datetime.now()
print ("Code 60 activé à ", c60d.strftime("%H:%M:%S"))
saisie=input("Tapez entree pour la fin du code 60, X pour sortir : ")
c60f=datetime.now()
print("Debut ", c60d.strftime("%H:%M:%S"))
print("Fin ", c60f.strftime("%H:%M:%S"))
c60x=c60f-c60d
print("Duree ", c60duree(c60x))
print("-------------")
c60[0].append(c60d)
c60[1].append(c60f)
#del(c60[0],[-1])
#del(c60[1],[-1])
#return
def relais():
print("Relais pilote demarré ")
relh=datetime.now()
relv=input("Quelle voiture ? ")
relp=input("Quel pilote repart ? ")
rele=input("Quantité d'essence ? ")
input("Tapez entrée à la sortie des stands ")
rels=datetime.now()
rel[0].append(relh), rel[1].append(relv), rel[2].append(relp), rel[3].append(rele), rel[4].append(rels)
print("Dureé ", rels-relh)
print(*rel)
#def essence():
#ess=[[],[],[],[]]
#print("Ravitaillement essence demarré ")
#essh=datetime.now()
#essv=input("Quelle voiture ? ")
#essp=input("Quel pilote ? ")
#essq=input("Combien de litres ? ")
#ess[0].append(essh), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq)
#print(*ess)
def essenceResult(ess, ent0, ent1, ent2, ent3):
ess_e = ent0.get()
essv = ent1.get()
essp = ent2.get()
essq = ent3.get()
ess_s = datetime.now()
ess[0].append(ess_e), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq), ess [4].append(ess_s)
resultLabel = Label(Frame4, text = str(*ess))
resultLabel.grid(row = 5, column = 0, columnspan = 2)
def essence():
print("yr")
ess_e=datetime.now()
Frame4.grid(row = 1, column = 0)
Label1 = Label(Frame4, text = "Ravitaillement demarré ")
Label1.grid(row = 0, column = 0, columnspan = 2)
essvLabel = Label(Frame4, text = "Quelle voiture ? ")
essvEntry = Entry(Frame4)
essvLabel.grid(row = 1, column = 0)
essvEntry.grid(row = 1, column = 1)
essvEntry.focus()
#root.bind_all("<Return>", function)
esspLabel = Label(Frame4, text = "Quel pilote part ? ")
esspEntry = Entry(Frame4)
esspLabel.grid(row = 2, column = 0)
esspEntry.grid(row = 2, column = 1)
esspEntry.focus()
essqLabel = Label(Frame4, text = "Combien de litres ? ")
essqEntry = Entry(Frame4)
essqLabel.grid(row = 3, column = 0)
essqEntry.grid(row = 3, column = 1)
essqEntry.focus()
submitButton = Button(Frame4, text = "Sortie des stands", command = lambda: essenceResult(ess, ess_e, essvEntry, esspEntry, essqEntry))
submitButton.grid(row = 4, column = 0, columnspan = 2)
fenetre = Tk()
fenetre['bg']='grey'
# frame 1
Frame1 = Frame(fenetre, bg="green", borderwidth=1, relief=GROOVE)
Frame1.grid(row = 0, column = 0, padx=5, pady=5)
# frame 2
Frame2 = Frame(fenetre, bg="yellow", borderwidth=1, relief=GROOVE)
Frame2.grid(row = 0, column = 1, padx=5, pady=5)
# frame 3
Frame3 = Frame(fenetre, bg="purple", borderwidth=1, relief=GROOVE)
Frame3.grid(row = 0, column = 2, padx=5, pady=5)
Frame4 = Frame(fenetre)
Fenetre = Tk()
fenetre['bg']='grey'
# Ajout de labels
Button(Frame1, text="Essence", command=essence).pack(padx=300, pady=100)
Button(Frame2, text="Relais", command=relais).pack(padx=300, pady=100)
Button(Frame3, text="Code 60", command=code60).pack(padx=300, pady=100)
Here's the fixed code:
def essenceResult(ess, ess_e, ent1, ent2, ent3):
essv = ent1.get()
essp = ent2.get()
essq = ent3.get()
ess_s = datetime.now()
ess[0].append(ess_e), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq), ess[4].append(ess_s)
resultLabel = Label(Frame4, text = str(ess))
resultLabel.grid(row = 5, column = 0, columnspan = 2)
def essence():
print("yr")
ess_e=datetime.now()
Frame4.grid(row = 1, column = 0)
Label1 = Label(Frame4, text = "Ravitaillement demarré ")
Label1.grid(row = 0, column = 0, columnspan = 2)
essvLabel = Label(Frame4, text = "Quelle voiture ? ")
essvEntry = Entry(Frame4)
essvLabel.grid(row = 1, column = 0)
essvEntry.grid(row = 1, column = 1)
essvEntry.focus()
esspLabel = Label(Frame4, text = "Quel pilote part ? ")
esspEntry = Entry(Frame4)
esspLabel.grid(row = 2, column = 0)
esspEntry.grid(row = 2, column = 1)
esspEntry.focus()
essqLabel = Label(Frame4, text = "Combien de litres ? ")
essqEntry = Entry(Frame4)
essqLabel.grid(row = 3, column = 0)
essqEntry.grid(row = 3, column = 1)
essqEntry.focus()
submitCommand = lambda event = None: essenceResult(ess, ess_e, essvEntry, esspEntry, essqEntry)
submitButton = Button(Frame4, text = "Sortie des stands", command = submitCommand)
Frame4.bind_all("<Return>", submitCommand)
submitButton.grid(row = 4, column = 0, columnspan = 2)
You also need to remove the extra Fenetre = Tk() after Frame4, as this will break it. (You can only have one Tk(), if you want more windows use Toplevel())The first problem is solved by adding Frame4.bind_all("<Return>", submitCommand). Now when you press enter it will run submitCommand, which will run essenceResult.
The second problem was using .get() on a datetime.datetime object. You can't use .get() because it isn't an entry. Instead, just have it as a parameter and don't change it. You only need .get() to get the values from a Tkinter Entry.

local variable referenced before assignment - Surely not this difficult

I'm trying to write a script to control movements of a camera. I'm writing it in Thonny on a Raspberry Pi. I receive the following error when trying to move the camera using the GUI buttons. I've asked around and tried troubleshooting the problem but no luck yet.
if anyone can help that'd be awesome.
I appreciate there are alternative workflows to this script but it's me combining an old script with a new GUI so I'd love to see if they could be merged. If not oh well, I'll implement the other workflow.
[Here is the error message from Thonny][1]
from tkinter import *
import RPi.GPIO as GPIO
import time
import datetime, sys, tty, termios
#defining root
root = Tk()
root.title('Operation Little Brother V02')
#setting GPIO board
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3,GPIO.OUT)
servo1 = GPIO.PWM(3, 50)
GPIO.setup(5,GPIO.OUT)
servo2 = GPIO.PWM(5, 50)
#setting servos to off
servo1.start(0)
servo2.start(0)
#user input section
dummy = input('Initiate project. Press Enter')
#setting servos to 90degrees/startup sequence
print('launching start up sequence')
servo1.ChangeDutyCycle(6)
time.sleep(1)
servo1.ChangeDutyCycle(0)
time.sleep(1)
print ('servo 1 test complete')
servo2.ChangeDutyCycle(6)
time.sleep(1)
servo2.ChangeDutyCycle(0)
print ('servo 2 test complete')
# Defining Functions
#x axis movement concept
def x_movement(x_dir):
if x_axis <= limit_x_left and x_axis >= limit_x_right:
x_axis = x_axis + x_dir
servo1.ChangeDutyCycle(x_axis)
time.sleep(0.3)
servo1.ChangeDutyCycle(0)
time.sleep(0.5)
print ('moved camera to position: ' +str(x_axis) + '/' +str(limit_x_left))
return
else:
print ('limits reached')
#y axis movement concept
def y_movement(y_dir):
if y_axis <= limit_y_down and y_axis >= limit_y_up:
y_axis = y_axis + y_dir
servo2.ChangeDutyCycle(y_axis)
time.sleep(0.3)
servo2.ChangeDutyCycle(0)
time.sleep(0.5)
print('moved camera to position: ' +str(y_axis) + '/' +str(limit_y_up))
return y_axis
else:
print ('limits reached')
#centre movement
def centre_movement():
y_axis = 6
servo2.ChangeDutyCycle(6)
servo2.ChangeDutyCycle(0)
time.sleep(0.5)
x_axis = 6
servo1.ChangeDutyCycle(6)
servo1.ChangeDutyCycle(0)
time.sleep(0.5)
print('camera centered to position 6')
return
#off sequence
def off():
servo1.ChangeDutyCycle(0)
servo2.ChangeDutyCycle(0)
servo1.stop()
servo2.stop()
GPIO.cleanup()
print('Whoopty fucking doo it\'s finished')
exit()
#defining limits for x and y axis
limit_x_left = 9
limit_x_right = 3
limit_y_up = 3
limit_y_down = 9
x_axis = 6
y_axis = 6
#frame creation
frame1 = LabelFrame(root, text = 'Welcome to Operation Little Brother', padx = 25, pady = 25, border = 5, fg = '#ffffff', bg = '#3e556b')
#button creation
button1_left = Button(frame1, text = 'Left', padx = 20, pady = 20, fg = 'purple', bg = '#63778a', command = lambda: x_movement(1))
button2_right = Button(frame1, text = 'Right', padx = 20, pady = 20, fg = 'orange', bg = '#63778a', command = lambda: x_movement(-1))
button3_up = Button(frame1, text = 'Up', padx = 20, pady = 20, fg = 'green', command = lambda: y_movement(1))
button4_down = Button(frame1, text = 'Down', padx = 20, pady = 20, fg = 'blue', command = lambda: y_movement(-1))
button5_centre = Button(frame1, text = 'Centre', padx = 20, pady = 20, fg = 'black', command = lambda: centre_movement())
button6_start = Button(frame1, text = 'Start', padx = 10, pady = 10, fg = 'green')
button7_stop = Button(frame1, text = 'Stop', padx = 10, pady = 10, fg = 'red', command = lambda: off())
#positioning the frame
frame1.pack()
#button positioning
button1_left.grid(row = 3, column = 0,)
button2_right.grid(row = 3, column = 2,)
button3_up.grid(row = 2, column = 1)
button4_down.grid(row = 4, column = 1)
button5_centre.grid(row = 3, column = 1)
button6_start.grid(row = 1, column = 0)
button7_stop.grid(row = 1, column = 2)
#Text formatting
button1_left.configure(font='Calibri 15')
button2_right.configure(font='Calibri 15')
button3_up.configure(font='Calibri 15')
button4_down.configure(font='Calibri 15')
button5_centre.configure(font='Calibri 15')
button6_start.configure(font='Calibri 15')
button7_stop.configure(font='Calibri 15')
# Window Loop
root.mainloop()
[1]: https://i.stack.imgur.com/xIc0O.png

How to change background color in ttk python

I've made a simple gui age converter app but i want to change its bg color to black.
The problem is in the ttk frame.i don't know how to configure its bg color.
I have tried different methods but that didn't work.
i would be grateful if you guys could help.
here is the code
from tkinter import *
from tkinter import ttk
from PIL import Image
def calculate(*args):
try:
age_sec = int(age.get())
age_sec = age_sec * 12 * 365 * 24 * 60 * 60
age_seconds.set(age_sec)
except:
age_seconds.set('Either the field is empty or \n value is not numeric.')
root = Tk()
root.title("Converter")
root.configure(background="black")
mainframe = ttk.Frame(root, padding = "6 6 12 12")
mainframe.grid(column = 0, row = 0, sticky = (N, W, E, S))
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)
#mainframe['borderwidth'] = 2
#mainframe['relief'] = 'groove'
age = StringVar()
age_seconds = StringVar()
ttk.Label(mainframe, foreground = "#4D4E4F", text = "Enter your Age: ").grid(column = 1, row = 1, sticky = E)
age_entry = ttk.Entry(mainframe, width = 30, textvariable = age)
age_entry.grid(column = 2, row = 1, sticky = (W, E))
ttk.Label(mainframe, foreground = "#4D4E4F", text = "your age in seconds is ").grid(column = 1, row = 2, sticky = (E))
ttk.Label(mainframe, textvariable = age_seconds, background = "lightyellow", foreground = "#727475", width = 30).grid(column = 2, row = 2, sticky = W)
#Mouse Events...\\
butt_image = PhotoImage(file = 'images.gif')
ttk.Button(mainframe, compound = TOP, text = "Hit Now", image =butt_image, cursor = "hand2", width= 30, command = calculate).grid(column = 2, row = 4, sticky = W)
l2 = ttk.Label(mainframe,foreground = "#4D4E4F", text = "Mouse Events: ").grid(column = 1, row = 3, sticky = E)
l = ttk.Label(mainframe,background = "lightyellow", foreground = "#727475", text = 'Measurement is starting...', width = 30)
l.grid(column = 2, row = 3, sticky = W)
l.bind('<Enter>', lambda e: l.configure(text = 'Moved Mouse Inside'))
l.bind('<Leave>', lambda e: l.configure(text = 'Mouse Moved Out'))
l.bind('<1>', lambda e: l.configure(text = 'left Mouse clicked'))
l.bind('<Double-1>', lambda e: l.configure(text = 'Double clicked'))
l.bind('<B1-Motion>', lambda e: l.configure(text = 'Left button drag to %d, %d' %(e.x, e.y)))
image = PhotoImage(file = 'waves.gif')
ttk.Label(mainframe, compound = CENTER, text = "Image text", font = ('roman', 9, 'normal'), foreground ='green', image = image).grid(column = 3, row = 1, sticky = (N, E))
#if '__name__' == '__main__':
for child in mainframe.winfo_children(): child.grid_configure(padx = 15, pady = 15)
age_entry.focus()
root.bind('<Return>', calculate)
root.mainloop()
A ttk.Frame does not have a background / bg option. To change it you need to use style.
See ttk.Frame Info
If you don't really need to use a ttk.Frame you can just switch to a tkinter.Frame

updating tkinter window for text background changes

Trying to show a green or red background in the text field of the answer to the simple addition quizzer.
Currently in PyCHarm complains that:
Entry.grid_configure(background = "red")
TypeError: grid_configure() missing 1 required positional argument: 'self'
0
I can't seem to figure this out. Any help is appreciated.
Here's the code so far:
from tkinter import *
import random
class MainGUI:
def __init__(self):
window = Tk() # Create the window
window.title("Addition Quizzer") # Set the title
#window.width(len(window.title()))
self.number1 = random.randint(0, 9)
self.number2 = random.randint(0, 9)
Label(window, text = "+").grid(row = 2, column = 1, sticky = E)
Label(window, text = "Answer").grid(row = 3, column = 1, sticky = W)
self.firstNumber = StringVar()
Label(window, text = self.number1, justify = RIGHT).grid(row = 1, column = 2)
self.secondNumber = StringVar()
Label(window, text = self.number2, justify = RIGHT).grid(row = 2, column = 2)
self.entry = StringVar()
Entry(window, textvariable = self.entry, justify = CENTER, width = 4, background = "grey").grid(row = 3, column = 2)
Button(window, text = "Answer:", command = self.computeAnswer).grid(row = 4, column = 1, sticky = E)
self.result = StringVar()
Label(window, textvariable = self.result).grid(row = 4, column = 2)
window.mainloop() # Create the event loop
def computeAnswer(self):
self.result.set(format(self.number1 + self.number2))
if self.entry == self.result:
self.displayCorrect()
else:
self.displayIncorrect()
def displayCorrect(self):
# self.correctAnswer = "Correct"
# Label(self.window, text = self.correctAnswer, background = "green", justify = RIGHT).grid(row = 5, column = 2)
Entry.grid_configure(background = "green")
def displayIncorrect(self):
# self.incorrectAnswer = "Incorrect"
# Label(self.window, text = self.incorrectAnswer, background = "red", justify = RIGHT).grid(row = 5, column = 2)
Entry.grid_configure(background = "red")
MainGUI()
If you had read and followed this in the Help Center material, you would have reduced your code to the following, which still gets the same error message.
from tkinter import *
Entry.grid_configure()
The message refers to the fact that Python instance methods require an instance. This is usually done by calling the method on an instance instead of the class. Otherwise, an instance must be given as the first argument. Consider
mylist = []
mylist.append(1)
list.append(mylist, 2)
print(mylist)
# [1, 2]
You need to save a reference to your Entry box. Change
Entry(window, ..., background = "grey").grid(...)
to
self.entry = Entry(window, ..., background = "grey").grid(...)
I do not know if calling .grid_configure(background=color will do what you want.
This will, I am sure.
self.entry['background'] = 'red'

Resources