Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    May 2018
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    URGENT [ Python project ] - Problem.

    Hi there, I am going to try to make this as short as possible. I have an assignment due in 2 days and I have a Huge problem. Basically it is time.sleep . Whenever I run my program everything works fine, unless I add time.sleep . My program starts lagging and does not function correctly. For example, I want to change the label every 1 second. This is for a countdown that I want to display. But instead what happens is the program starts lagging and it only shows the last label. Could anyone help me with this ? PS: Sorry about the extremely messy code. I am using Tkinter and Python 3.7

    Code:
    rom tkinter import *
    from tkinter import messagebox
    import time
    import sys
    
    import tkinter as tk
    count = 0
    master = Tk()
    photo=PhotoImage(file="Play.png")
    
    dictionary = ["The", "best", "fox", "has", "earned", "a", "mean", "meal", "while", "deciding", "too"]
    usersinput = []
    
    filename = PhotoImage(file = "background.png")
    menu = PhotoImage(file="banner-main-menu.png")
    filename2 = PhotoImage(file = "background2.png")
    background_label = Label(master, image=filename)
    background_label.place(x=0, y=0, relwidth=1, relheight=1)
    filename3= PhotoImage(file="mainback.png")
    filename4= PhotoImage(file="score.png")
    filename5= PhotoImage(file="highscore.png")
    filename6= PhotoImage(file="mainmenubtn.png")
    filename7= PhotoImage(file="Highscoreback.png")
    filename8= PhotoImage(file="main_menu2.png")
    filename9= PhotoImage(file="Highscore2nd.png")
    filename10= PhotoImage(file="score2nd.png")
    filename11= PhotoImage(file="play2.png")
    filename12= PhotoImage(file="red-rectangle-clipart-1.jpg")
    filename13= PhotoImage(file="line-27325_960_720.png")
    filename14= PhotoImage(file="back5.png")
    filename15= PhotoImage(file="back4.png")
    filename16= PhotoImage(file="startbtn.png")
    
    def protocolhandler():
        if messagebox.askokcancel("Exit", "Wanna leave?"):
                if messagebox.askokcancel("Exit", "Are you sure?"):
                        master.destroy()
    
    
    Canvas = Canvas(master, width=800, height=600)
    master.geometry("800x600+0+0")
    Canvas.place
    helpname= PhotoImage(file= "Help.png")
    
    def restart_program():
        """Restarts the current program.
        Note: this function does not return. Any cleanup action (like
        saving data) must be done before calling this function."""
        python = sys.executable
    image = "old"
    def play():
        #score = 0
        count = 0
        #while score == 0:
            #click
        def highscore():
            background_label3 = Label(master, image=filename7)
            background_label3.place(x=0, y=0, relwidth=1, relheight=1)
            mainmenu_button = Button(master, image=filename6, height=77, width=198, command=main_menu)
            mainmenu_button.place(x=300, y=400)
        background_label3 = Label(master, image=filename3)
        background_label3.place(x=0, y=0, relwidth=1, relheight=1)
        background_label22 = Label(master, image=filename13)
        background_label22.place(x=177, y=230, width=40, height=5)
        def countdown():
            countdowntext = Label(master, text="Hello, world!")
            countdowntext.place(x=200, y=200)
            time.sleep(1)
            countdowntext = Label(master, text="DIFFERENT TEXT!")
            countdowntext.place(x=200, y=200)
        startbtn = Button(master,image=filename16, height=56, width=130, command = countdown)
        startbtn.place(x=320,y=460)
        def red():
            sys.stdout.flush()
            print("test")
            background_label = Label(master, image=filename12)
            background_label.place(x=130, y=530, height=30, width=500)
        e1 = Entry(master)
        e1.place(x=130,y=530,width=500, height=30)
        count = 0
        def getinfo(event):
            global linecount
            global count
            print(count)
            userword = e1.get()
            print(dictionary[count])
            if userword[:-1] == dictionary[count]:
                count = count + 1
                print(usersinput)
            print(userword)
            if count == 1:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 2:
                background_label22.place(x=285, y=230, width=40, height=5)
            if count == 3:
                background_label22.place(x=330, y=230, width=40, height=5)
            if count == 4:
                background_label22.place(x=380, y=230, width=70, height=5)
            if count == 5:
                background_label22.place(x=460, y=230, width=18, height=5)
            if count == 6:
                background_label22.place(x=485, y=230, width=55, height=5)
            if count == 7:
                background_label22.place(x=550, y=230, width=55, height=5)
            if count == 8:
                background_label22.place(x=180, y=258, width=55, height=5)
            if count == 9:
                background_label22.place(x=245, y=258, width=80, height=5)
            if count == 10:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 11:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 12:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 13:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 14:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 15:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 16:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 17:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 18:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 19:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 20:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 21:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 22:
                background_label22.place(x=225, y=230, width=50, height=5)
            if count == 23:
                background_label22.place(x=225, y=230, width=50, height=5)
            e1.delete(0, END)
            e1.insert(0, "")
        master.bind("<space>", getinfo)
        score = Button(master,image=filename4, height=77, width=198, command=main_menu)
        score.place(x=50,y=35)
        def motion_main(event):
            mainmenu_button.configure(image=filename8, height=77, width=198)
        def leave_main(event):
            mainmenu_button.configure(image=filename6, height=77, width=198)
        def motion_high(event):
            highscore.configure(image=filename9, height=77, width=198)
        def leave_high(event):
            highscore.configure(image=filename5, height=77, width=198)
        def motion_score(event):
            score.configure(image=filename10, height=77, width=198)
        def leave_score(event):
            score.configure(image=filename4, height=77, width=198)
        highscore = Button(master,image=filename5, height=77, width=198, command=highscore)
        highscore.place(x=300,y=35)
        mainmenu_button = Button(master,image=filename6, height=77, width=198, command=main_menu)
        mainmenu_button.place(x=550,y=35)
        mainmenu_button.bind('<Motion>', motion_main)
        mainmenu_button.bind('<Leave>', leave_main)
        highscore.bind('<Motion>', motion_high)
        highscore.bind('<Leave>', leave_high)
        score.bind('<Motion>', motion_score)
        score.bind('<Leave>', leave_score)
    
    def main_menu():
        background_label = Label(master, image=filename)
        background_label.place(x=0, y=0, relwidth=1, relheight=1)
        help_button = Button(master, image=helpname, height=54, width=144,command=lambda:help(menu))
        help_button.place(x=40,y=430)
        b = Button(master,image=photo, height=54, width=144, command=play)
        b.place(x=600,y=430)
    
    def help(menu):
        background_label2 = Label(master, image=filename2)
        background_label2.place(x=0, y=0, relwidth=1, relheight=1)
        menu_button = Button(master, image=menu, height=50, width=300,command = main_menu)
        menu_button.place(x=250,y=520)
    
    
    help_button = Button(master, image=helpname, height=54, width=144,command=lambda:help(menu))
    help_button.place(x=40,y=430)
    
    b = Button(master,image=photo, height=54, width=144,command=play)
    b.place(x=600,y=430)
    master.protocol("WM_DELETE_WINDOW", protocolhandler)
    mainloop()
    Last edited by vinyl-junkie; Aug 4th, 2018 at 04:34 AM. Reason: added code tags


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •