I am using python to create a self checkout kiosk application but it has a very bloated (inefficient) main screen where the user selects the items. When passing between the main menu and the main screen, the console displays that it has accepted the user number and intends to move to the next screen although the system freezes and never makes it. both applications work separately although this seems to be a system error that I am not sure how to resolve. (This system has the buttons hard coded into the UI). (Not sure how to make the MRP without showing the full extent of the problem so please don't flag it) The main menu file is as follows: (The admin code is 1234567890987654321)
"""
This file is the executable file which calls all other files including the
full application.
"""
#The following imports are modules which have prewritten
#functions which I am able to use. They came predownloaded
#with python as well as downloading some from pygame.org
import pygame, sys
from Assistance import Text
#import read
mainClock = pygame.time.Clock()
#setting window
from pygame.locals import *
#The following are Constants which are defined here for easier maintanence
click = bool
pygame.init()
pygame.display.set_caption('LeVOGUE')
clock = pygame.time.Clock()
screen = pygame.display.set_mode((1200, 800), 0, 32)
windowSurface = pygame.display.set_mode((1200, 650), pygame.DOUBLEBUF)
run = 2
font = pygame.font.SysFont(None, 35)
font2 = pygame.font.SysFont(None, 70)
base_font = pygame.font.Font(None, 50)
base_font2 = pygame.font.Font(None, 160)
user_text= ''
input_rect = pygame.Rect(405,330,600,42)
Bags_tick_rect = pygame.Rect(950,413,35,35)
Bags_rect = pygame.Rect(405,410,600,42)
HELP_rect = pygame.Rect(755,550,160,45)
Outline_rect = pygame.Rect(10,10,1180,630)
color_active = pygame.Color('lightskyblue3')
color_passive = pygame.Color('gray15')
color = color_passive
Colour = pygame.Color(0,0,0)
bags = int()
found =False
count = 1
s = " "
num = 1
keys = pygame.key.get_pressed()
click = pygame.MOUSEBUTTONDOWN
Volume = True
active = False
#tick_active = False
Item1 = ''
Item2 = ''
Item3 = ''
Item4 = ''
Item5 = ''
Item6 = ''
Item7 = ''
Item8 = ''
Item9 = ''
Item10 = ''
Item11 = ''
Item12 = ''
Total_Qty = ''
Total_Items = ''
#This is responsible fo importing the mixer module
from pygame import mixer
#Load music file
mixer.music.load("MainMenuMusic.mp3")
#play music file
mixer.music.play()
def Check(user_text, found):
global count, s
print("button2")
#while looking for line
fh =open("user_info.txt", "r")
while found == False:
s =fh.readline()
#seperate the words
N=s.split("~")
#if its found
if str(user_text) in N:
found = True
print ("line Number:", count, ":", s)
count+=1
fh.close()
return found
def main_menu():
#this area of the code was reused from a previous file
#which is an example of the RAD approach.
#~~~~~~~~~~~~~~~~~Start Code applied from previous programs~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
global click
global user_text
global color
global active
global bags
global found
global count
global fh
global num
user_text = ''
#This checkbox is imported from a module found within the LeVOGUE folder
#The checkbox file is imported above and called with the function checkbox
while True:
#Defining Quit
for event in pygame.event.get():
if event.type == QUIT:
print("Quit")
pygame.quit()
sys.exit()
#~~~~~~~~~~~~~~~~~~~~~~~~End Code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#updating checkbox
#defining if click on the text box
if event.type == pygame.MOUSEBUTTONDOWN:
if input_rect.collidepoint(event.pos):
#updating the variable
active = True
else:
active = False
#If a key is pressed
if event.type == pygame.KEYDOWN:
if active == True:
#if its backspace, delete it
if event.key == pygame.K_BACKSPACE:
user_text=user_text[:-1]
else:
#if the size is small enoguh, type the text
if text_surface.get_width() <= 410:
user_text+= event.unicode
#if key escape key is pressed, Quit
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_RETURN:
user_text = user_text[:-1]
Check(user_text, s, found)
#if click, click is true
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
click = True
if click:
print(pygame.mouse.get_pos())
#Background colour
screen.fill((255, 255, 255))
#define the colours for the text box
if active:
color = color_active
else:
color = color_passive
#draw a rectangle
pygame.draw.rect(screen,color,input_rect,2)
#if there is no text, display instructions
if user_text == '':
text_surface_empty = base_font.render("ENTER USER NUMBER:", True, (0,0,0))
screen.blit(text_surface_empty, (410,335))
#display text entered
text_surface = base_font.render(user_text, True, (0, 0, 0))
screen.blit(text_surface, (input_rect.x +5, input_rect.y +5))
#input_rect.w = max(50, text_surface.get_width() +10)
#mouse position
mx, my = pygame.mouse.get_pos()
#~~~~~~~~~~~~~~Start code applied from tutorial ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Location and size of button (not picture)
button_2 = pygame.Rect(1100, 330, 60, 42)
#What happens if the mouse click is over buttons listed above
if button_2.collidepoint(mx, my):
if click:
print("Button_2 clicked")
from Search import Check
found = Check(user_text, found)
if found == True:
from MainScreen import Main_sales
Main_sales(Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8, Item9, Item10, Item11, Item12)
print("main_sales")
elif user_text == '1234567890987654321':
from Admin_Menu import admin_screen
admin_screen()
else:
Text("Not Found", "calibri 80", "white", "black")
#draw rectangles on screen
pygame.draw.rect(screen, (25, 255, 255), button_2)
#~~~~~~~~~~~~~~~~~~ End Code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#load picture
#Text and the background colour fonttype(text, Makes the text neater, colour)
text_surface_account = font2.render("->", True, (0,0,0))
screen.blit(text_surface_account, (1107,325))
#draw rectangles on screen(where,colour,size, thickness of line)
click = False
#update screen
pygame.display.update()
mainClock.tick(60)
#The following code was derived from a tutorial which allows the application
#to quit without causing any error codes.
#~~~~~~~~~~~~Start code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def Quit():
running = True
while running:
pygame.quit()
quit()
#~~~~~~~~~~~ End Code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pygame.display.update()
mainClock.tick(60)
#run the main menu
main_menu()
pygame.quit()
sys.exit()
"""Credits:
The LionHead image associated with the LeVOGUE brand is obtained under the creative
commons lisence, accessable through this website
https://freepngimg.com/png/22685-lion-head-image
"""
The main screen is as follows:
# window ----------------------------------------
"""
This file is the executable file which calls all other files including the
full application.
"""
import pygame, sys
import tkinter as tk
from tkinter import Tk, Canvas, Frame, BOTH
from tkinter import ttk
from tkinter import *
from collections import Counter as count
from datetime import datetime
import time
import string
#import read
mainClock = pygame.time.Clock()
#setting window
from pygame.locals import *
#The following are Constants which are defined here for easier maintanence
click = bool
pygame.init()
pygame.display.set_caption('LeVOGUE')
clock = pygame.time.Clock()
screen = pygame.display.set_mode((1200, 800), 0, 32)
windowSurface = pygame.display.set_mode((1200, 650), pygame.DOUBLEBUF)
run = 2
font = pygame.font.SysFont(None, 35)
font2 = pygame.font.SysFont(None, 70)
font3 = pygame.font.SysFont(None, 25)
base_font = pygame.font.Font(None, 50)
base_font2 = pygame.font.Font(None, 160)
Item1 = ''
Item2 = ''
Item3 = ''
Item4 = ''
Item5 = ''
Item6 = ''
Item7 = ''
Item8 = ''
Item9 = ''
Item10 = ''
Item11 = ''
Item12 = ''
Item1_rect = pygame.Rect(780, 33, 400, 547)
Item2_rect = pygame.Rect(780, 58, 400, 547)
Item3_rect = pygame.Rect(780, 83, 400, 547)
Item4_rect = pygame.Rect(780, 108, 400, 547)
Item5_rect = pygame.Rect(780, 133, 400, 547)
Item6_rect = pygame.Rect(780, 158, 400, 547)
Item7_rect = pygame.Rect(780, 183, 400, 547)
Item8_rect = pygame.Rect(780, 208, 400, 547)
Item9_rect = pygame.Rect(780, 233, 400, 547)
Item10_rect = pygame.Rect(780, 258, 400, 547)
Item11_rect = pygame.Rect(780, 283, 400, 547)
Item12_rect = pygame.Rect(780, 308, 400, 547)
Outline_rect = pygame.Rect(10,10,1180,630)
current_textbox = 0
Colour = pygame.Color(0,0,0)
found =False
#key_text_num = 2
s = " "
fh =open("user_info.txt", "r")
keys = pygame.key.get_pressed()
click = pygame.MOUSEBUTTONDOWN
Volume = True
active = False
#tick_active = False
#This is responsible fo importing the mixer module
from pygame import mixer
#Load music file
#mixer.music.load("MainMenuMusic.mp3")
#play music file
#mixer.music.play()
sc1_num = 0
sc1_price = 0
sc2_num = 0
sc2_price = 0
sc3_num = 0
sc3_price = 0
sc4_num = 0
sc4_price = 0
sc5_num = 0
sc5_price = 0
sc6_num = 0
sc6_price = 0
sc7_num = 0
sc7_price = 0
sc8_num = 0
sc8_price = 0
sc9_num = 0
sc9_price = 0
sc10_num = 0
sc10_price = 0
sc11_num = 0
sc11_price = 0
sc12_num = 0
sc12_price = 0
Total_Qty = 0
Total_Items = 0
CLICKED_BUTTON_3 = False
CLICKED_BUTTON_4 = False
CLICKED_BUTTON_5 = False
CLICKED_BUTTON_6 = False
CLICKED_BUTTON_7 = False
CLICKED_BUTTON_8 = False
CLICKED_BUTTON_9 = False
CLICKED_BUTTON_10 = False
CLICKED_BUTTON_11 = False
CLICKED_BUTTON_12 = False
CLICKED_BUTTON_13 = False
CLICKED_BUTTON_14 = False
def Main_sales(Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8, Item9, Item10, Item11, Item12):
#this area of the code was reused from a previous file
#which is an example of the RAD approach.
#~~~~~~~~~~~~~~~~~Start Code applied from previous programs~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
global Item1_rect,Item2_rect,Item3_rect,Item4_rect,Item5_rect,Item6_rect,Item7_rect,Item8_rect,Item9_rect,Item10_rect,Item11_rect,Item12_rect
global click
global active
global bags
global current_time
global found
global count
global s
global fh
global i_a
global key_text_num
global sc1_num, sc1_price, current_textbox, CLICKED_BUTTON_3
Total_Qty = 0
Total_Items = 0
#This checkbox is imported from a module found within the LeVOGUE folder
#The checkbox file is imported above and called with the function checkbox
while True:
#Defining Quit
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("Quit")
pygame.quit()
sys.exit()
#~~~~~~~~~~~~~~~~~~~~~~~~End Code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#if key escape key is pressed, Quit
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
#if click, click is true
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
click = True
if click:
print(pygame.mouse.get_pos())
#Background colour
screen.fill((255, 255, 255))
text1_surface = font.render(Item1, True, (0,0,0))
screen.blit(text1_surface, (Item1_rect.x+20 , Item1_rect.y +100))
#mouse position
mx, my = pygame.mouse.get_pos()
#~~~~~~~~~~~~~~Start code applied from tutorial ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#have each text box be represented in an array and check the array for the next empty bucket
b_w = 180
b_h = 70
b3_x = 55
b3_y = 200
button_3 = pygame.Rect( b3_x, b3_y ,b_w, b_h)
found = False
if Item1 == '':
current_textbox = 0
elif Item2 == '':
current_textbox = 1
elif Item3 == '':
current_textbox = 2
elif Item4 == '':
current_textbox = 3
elif Item5 == '':
current_textbox = 4
elif Item6 == '':
current_textbox = 5
elif Item7 == '':
current_textbox = 6
elif Item8 == '':
current_textbox = 7
elif Item9 == '':
current_textbox = 8
elif Item10 == '':
current_textbox = 9
elif Item11 == '':
current_textbox = 10
elif Item12 == '':
current_textbox = 11
#print(current_textbox)
#What happens if the mouse click is over buttons listed above
if button_3.collidepoint(mx, my):
if click:
sc1_num = sc1_num+1
sc1_price = sc1_price+150
Button_3_text = (f"Scrunchie1 {sc1_num} ${sc1_price}")
if CLICKED_BUTTON_3 == False:
if current_textbox == 0:
Item1 = Button_3_text
button3 = 1
elif current_textbox == 1:
Item2 = Button_3_text
button3 = 2
elif current_textbox == 2:
Item3 = Button_3_text
button3 = 3
elif current_textbox == 3:
Item4 = Button_3_text
button3 = 4
elif current_textbox == 4:
Item5 = Button_3_text
button3 = 5
elif current_textbox == 5:
Item6 = Button_3_text
button3 = 6
elif current_textbox == 6:
Item7 = Button_3_text
button3 = 7
elif current_textbox == 7:
Item8 = Button_3_text
button3 = 8
elif current_textbox == 8:
Item9 = Button_3_text
button3 = 9
elif current_textbox == 9:
Item10 = Button_3_text
button3 = 10
elif current_textbox == 10:
Item11 = Button_3_text
button3 = 11
elif current_textbox == 11:
Item12 = Button_3_text
button3 = 12
else:
if button3 == 1:
Item1 =Button_3_text
if button3 == 2:
Item2 =Button_3_text
if button3 == 3:
Item3 =Button_3_text
if button3 == 4:
Item4 =Button_3_text
if button3 == 5:
Item5 =Button_3_text
if button3 == 6:
Item6 =Button_3_text
if button3 == 7:
Item7 =Button_3_text
if button3 == 8:
Item8 =Button_3_text
if button3 == 9:
Item9 =Button_3_text
if button3 == 10:
Item10 =Button_3_text
if button3 == 11:
Item11 =Button_3_text
if button3 == 12:
Item12 =Button_3_text
CLICKED_BUTTON_3 = True
#Cart
pygame.draw.rect(screen,Colour,pygame.Rect(780,30,400,550),2)
#button 2; Enter
#Draw boxes for the number buttons
pygame.draw.rect(screen, Colour, button_3, 2)
screen.blit((font3.render("Scrunchie1", True, (0,0,0))),(b3_x+20, b3_y+15))
#~~~~~~~~~~~~~~~~~~ End Code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#CART
pygame.draw.rect(screen,Colour,pygame.Rect(780,30,400,550),2)
pygame.draw.rect(screen,Colour,Outline_rect,2)
clock.tick(1)
theTime=time.strftime("%H:%M:%S", time.localtime())
timeText=font.render(str(theTime), True,(0,0,0),(255, 255, 255))
screen.blit(timeText, (1000,600))
click = False
#update screen
pygame.display.update()
pygame.display.flip()
mainClock.tick(60)
#The following code was derived from a tutorial which allows the application
#to quit without causing any error codes.
#~~~~~~~~~~~~Start code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def Quit():
running = True
while running:
pygame.quit()
quit()
#~~~~~~~~~~~ End Code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#run the main menu
Main_sales(Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8, Item9, Item10, Item11, Item12)
pygame.quit()
sys.exit()