Thanks for opening to help, I am a beginner programmer for a school major work and decided to do a checkout application. It isnt anything too fancy, most aspects are hard coded with some pieces being read from editable txt files. I am currently making the main system of the application where the user is able to select the item where it adds to their cart as well as checks to see if it is already in the cart to modify the cart as I don't want double ups on a piece of clothing.
###Tasks I am stuck on
- I am not able to get it to write to a new line (around 234) where it should accept \n, it doesn't work, rather it displays a box as if it doesn't understand the character. Possibly could be the character system I am using but I am not too sure. If something is in the cart and another thing is added, It isn't able to go back and modify what's already in the cart. (I am able to do it when nothing else is added after as It just replaces the text). my teacher / project supervisor also said to add an admin function where they are able to modify the Items, prices and pictures(if I add any) through a txt file.
- I am also wanting the cart to be on a scrolling screen that updates in size when necessary but this is an optional feature that I am going to look for tutorials unless one kind person can explain. The top rectangles are meant to take to another page with more options to chose from and I can't think of how to code this bit. I also kind of want date and time to be printed on the bottom right but this is a minor piece I know its a lot but I've got until late June to complete everything. Any advice is appreciated as it is still a big work in progress and I am only new to the language. Please let me know if you need any other information related.
Thanks Heaps!!!!! #Edit : added the picture Picture of the screen as is
# window ----------------------------------------
"""
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
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)
Item = ''
Item_rect = pygame.Rect(780, 33, 400, 547)
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
def Main_sales():
#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 Item
global active
global bags
global current_time
global found
global count
global s
global fh
global i_a
global key_text_num
global Item_rect
global sc1_num
global sc1_price
global sc2_num
global sc2_price
#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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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))
text_surface = font3.render(Item, True, (0,0,0))
screen.blit(text_surface, (Item_rect.x+20 , Item_rect.y +100))
#mouse position
mx, my = pygame.mouse.get_pos()
#This section of code was applied from a tutorial which I followed
#It was used to allow me to create rectangular buttons although it was
#heavily modified to add functionality to different buttons
#~~~~~~~~~~~~~~Start code applied from tutorial ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b_w = 180
b_h = 70
b2_x = 274
b2_y = 562
b2_w = 140
b2_h = 65
b3_x = 55
b3_y = 200
b4_x = 275
b4_y = 200
b5_x = 490
b5_y = 200
b6_x = 55
b6_y = 290
b7_x = 275
b7_y = 290
b8_x = 490
b8_y = 290
b9_x = 55
b9_y = 380
b10_x = 275
b10_y = 380
b11_x = 490
b11_y = 380
b12_x = 55
b12_y = 470
b13_x = 275
b13_y = 470
b14_x = 490
b14_y = 470
button_2 = pygame.Rect(b2_x, b2_y, b2_w, b2_h)
button_3 = pygame.Rect( b3_x, b3_y ,b_w, b_h)
button_4 = pygame.Rect( b4_x, b4_y ,b_w, b_h)
button_5 = pygame.Rect( b5_x, b5_y ,b_w, b_h)
button_6 = pygame.Rect( b6_x, b6_y ,b_w, b_h)
button_7 = pygame.Rect( b7_x, b7_y ,b_w, b_h)
button_8 = pygame.Rect( b8_x, b8_y ,b_w, b_h)
button_9 = pygame.Rect( b9_x, b9_y ,b_w, b_h)
button_10 = pygame.Rect( b10_x, b10_y ,b_w, b_h)
button_11 = pygame.Rect( b11_x, b11_y ,b_w, b_h)
button_12 = pygame.Rect( b12_x, b12_y ,b_w, b_h)
button_13 = pygame.Rect( b13_x, b13_y ,b_w, b_h)
button_14 = pygame.Rect( b14_x, b14_y ,b_w, b_h)
#What happens if the mouse click is over buttons listed above
if button_2.collidepoint(mx, my):
if click:
print("button2")
import MainMenu
if button_3.collidepoint(mx, my):
if click:
#while (sc_num < 10):
if (f"Scrunchie {sc1_num} ${sc1_price} ") in Item:
Item = Item[:-29]
sc1_num = sc1_num+1
sc1_price = sc1_price+15
Item = Item + (f"Scrunchie {sc1_num} ${sc1_price} \n")
print(" Button3")
if button_4.collidepoint(mx, my):
if click:
if (f"Scrunchie {sc2_num} ${sc2_price}") in Item:
Item = Item[:-39]
sc2_num = sc2_num+1
sc2_price = sc2_price+15
Item = Item + (f"Scrunchie2 {sc2_num} ${sc2_price}")
print(" Button4")
if button_5.collidepoint(mx, my):
if click:
print(" Button5")
if button_6.collidepoint(mx, my):
if click:
print(" Button6")
if button_7.collidepoint(mx, my):
if click:
print(" Button7")
if button_8.collidepoint(mx, my):
if click:
print(" Button8")
if button_9.collidepoint(mx, my):
if click:
print(" Button9")
if button_10.collidepoint(mx, my):
if click:
print(" Button10")
if button_11.collidepoint(mx, my):
if click:
print(" Button11")
if button_12.collidepoint(mx, my):
if click:
print(" Button12")
if button_13.collidepoint(mx, my):
if click:
print(" Button13")
if button_14.collidepoint(mx, my):
if click:
print(" Button14")
text_surface_Cart = font.render("Cart", True, (0,0,0))
text_surface_Item = font.render( "Item Qty Price", True, (0,0,0))
screen.blit(text_surface_Cart, (790,50))
screen.blit(text_surface_Item, (790, 100))
#for Button 2
text_surface_Enter = font2.render("Enter", True, (0,0,0))
screen.blit(text_surface_Enter, pygame.Rect((280, 565), (120, 70)))
#Cart
pygame.draw.rect(screen,Colour,pygame.Rect(780,30,400,550),2)
#button 2; Enter
pygame.draw.rect(screen, Colour , button_2, 2)
#Draw boxes for the number buttons
pygame.draw.rect(screen, Colour, button_3, 2)
pygame.draw.rect(screen, Colour, button_4, 2)
pygame.draw.rect(screen, Colour, button_5, 2)
pygame.draw.rect(screen, Colour, button_6, 2)
pygame.draw.rect(screen, Colour, button_7, 2)
pygame.draw.rect(screen, Colour, button_8, 2)
pygame.draw.rect(screen, Colour, button_9, 2)
pygame.draw.rect(screen, Colour, button_10, 2)
pygame.draw.rect(screen, Colour, button_11, 2)
pygame.draw.rect(screen, Colour, button_12, 2)
pygame.draw.rect(screen, Colour, button_13, 2)
pygame.draw.rect(screen, Colour, button_14, 2)
screen.blit((font3.render("Scrunchie1", True, (0,0,0))),(b3_x+20, b3_y+15))
screen.blit((font3.render("Scrunchie2", True, (0,0,0))),(b4_x+20, b4_y+15))
screen.blit((font3.render("Scrunchie3", True, (0,0,0))),(b5_x+20, b5_y+15))
screen.blit((font3.render("Scrunchie4", True, (0,0,0))),(b6_x+20, b6_y+15))
screen.blit((font3.render("Scrunchie5", True, (0,0,0))),(b7_x+20, b7_y+15))
screen.blit((font3.render("Shirt6", True, (0,0,0))),(b8_x+20, b8_y+15))
screen.blit((font3.render("Shirt7", True, (0,0,0))),(b9_x+20, b9_y+15))
screen.blit((font3.render("Shirt8", True, (0,0,0))),(b10_x+20, b10_y+15))
screen.blit((font3.render("Shirt9", True, (0,0,0))),(b11_x+20, b11_y+15))
screen.blit((font3.render("Pants10", True, (0,0,0))),(b12_x+20, b12_y+15))
screen.blit((font3.render("Pants11", True, (0,0,0))),(b13_x+20, b13_y+15))
screen.blit((font3.render("Pants11", True, (0,0,0))),(b14_x+20, b14_y+15))
#~~~~~~~~~~~~~~~~~~ End Code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ButtonBolt = pygame.image.load("LionsHEAD.png")
ButtonBolt = pygame.transform.scale(ButtonBolt, (120, 120))
screen.blit(ButtonBolt, (20,15))
text_surface_LeVOGUE = font2.render("LeVOGUE", True, (0,0,0))
screen.blit(text_surface_LeVOGUE, (140,55))
Key_Rect = pygame.Rect(260, 125, 230, 40)
pygame.draw.rect(screen, (0,0,0) , Key_Rect, 2)
Left_select_Rect = pygame.Rect(208, 125, 40, 40)
pygame.draw.rect(screen, (0,0,0), Left_select_Rect , 2)
text_surface_Left_select = font2.render("<", True, (0,0,0))
screen.blit(text_surface_Left_select, (215,118))
Right_select_Rect = pygame.Rect(502, 125, 40, 40)
pygame.draw.rect(screen, (0,0,0), Right_select_Rect , 2)
text_surface_Left_select = font2.render(">", True, (0,0,0))
screen.blit(text_surface_Left_select, (510,118))
#CART
pygame.draw.rect(screen,Colour,pygame.Rect(780,30,400,550),2)
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()
pygame.quit()
sys.exit()