微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

系统在尝试导入大量 python 文件时停止响应

如何解决系统在尝试导入大量 python 文件时停止响应

我正在使用 python 创建自助结账亭应用程序,但它有一个非常臃肿(低效)的主屏幕,用户可以在其中选择项目。在主菜单和主屏幕之间传递时,控制台显示它已接受用户号并打算移动到下一个屏幕,尽管系统冻结并且永远不会成功。这两个应用程序分别工作,尽管这似乎是一个我不知道如何解决系统错误。 (该系统将按钮硬编码到用户界面中)。 (不知道如何制作MRP而不显示问题的全部范围所以请不要标记它)主菜单文件如下:(管理员代码为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),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,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)
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))
            screen.blit(text_surface_empty,(410,335))


        #display text entered
        text_surface = base_font.render(user_text,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,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),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("->",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


"""


主画面如下:

# 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,pygame.DOUBLEBUF)

                                     
run = 2
font = pygame.font.SysFont(None,70)
font3 = pygame.font.SysFont(None,25)
base_font = 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,547)
Item3_rect = pygame.Rect(780,83,547)
Item4_rect = pygame.Rect(780,108,547)
Item5_rect = pygame.Rect(780,133,547)
Item6_rect = pygame.Rect(780,158,547)
Item7_rect = pygame.Rect(780,183,547)
Item8_rect = pygame.Rect(780,208,547)
Item9_rect = pygame.Rect(780,233,547)
Item10_rect = pygame.Rect(780,258,547)
Item11_rect = pygame.Rect(780,283,547)
Item12_rect = pygame.Rect(780,308,547)
Outline_rect = pygame.Rect(10,630)
current_textBox = 0

Colour = pygame.Color(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,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))

        text1_surface = font.render(Item1,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,550),2)
        #button 2; Enter
        #Draw Boxes for the number buttons
        pygame.draw.rect(screen,button_3,2)
        
        screen.blit((font3.render("Scrunchie1",0))),(b3_x+20,b3_y+15))
        
       
#~~~~~~~~~~~~~~~~~~ End Code applied from tutorial~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        

        


        
        #CART
        pygame.draw.rect(screen,2)
        pygame.draw.rect(screen,Outline_rect,2)

        clock.tick(1)
        theTime=time.strftime("%H:%M:%s",time.localtime())
        timeText=font.render(str(theTime),0),(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,Item12)
pygame.quit()
sys.exit()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。