Problem mit while-Schleife
Verfasst: Montag 30. August 2021, 12:43
Hallo Leute,
Ich möchte mir einen screen mit animierten Buchstaben basteln.
Es sollen einfach Buchstaben (Grafiken) im Bild hoch und runter laufen.
Folgendes Programm funktioniert aber nicht und ich finde den Grund nicht.
Wenn ich das über Pfeiltasten (mit bind) programmiere, läuft es, aber in einer Schleife hab ich nur noch einen weißen, eingefrorenen Bildschirm.
import time
from tkinter import *
from PIL import ImageTk, Image
main = Tk()
main.title("Test")
main.iconbitmap("prgpix/WindowIcon.ico")
main.geometry("1920x1200+0+0")
# main.wm_minsize(width=640, height=400) # wenn resizable = false, braucht man das hier ja nicht wirklich
main.resizable(width = False, height = False)
#main.configure(bg = "black")
hauptcanvas = Canvas(main, width = 1920, height = 1200, bd = 0, bg = "black", highlightthickness = 0)
hauptcanvas.place(x = 0, y = 0)
def startgedrueckt():
introscreen = False
introscreen = True
e1_pos = 200
c_pos = 250
k_pos = 300
e2_pos = 250
s_pos = 200
e1_pos_add = 1
c_pos_add = 1
k_pos_add = 1
e2_pos_add = 1
s_pos_add = 1
e_img = PhotoImage(file = "Stammtisch\Intro-E.png")
c_img = PhotoImage(file = "Stammtisch\Intro-C.png")
k_img = PhotoImage(file = "Stammtisch\Intro-K.png")
s_img = PhotoImage(file = "Stammtisch\Intro-S.png")
move_e1 = hauptcanvas.create_image(600, e1_pos, image=e_img, anchor="nw", tag="e1")
move_c = hauptcanvas.create_image(750, c_pos, image=c_img, anchor="nw", tag="c")
move_k = hauptcanvas.create_image(900, k_pos, image=k_img, anchor="nw", tag="k")
move_e2 = hauptcanvas.create_image(1050, e2_pos, image=e_img, anchor="nw", tag="e2")
move_s = hauptcanvas.create_image(1200, s_pos, image=s_img, anchor="nw", tag="s")
startbutton_img = ImageTk.PhotoImage(file="Stammtisch\STARTbutton.png")
startbutton = Button(hauptcanvas, borderwidth=0, bg="black", command=startgedrueckt)
startbutton.config(image=startbutton_img, activebackground="black")
startbutton.place(x=830, y=990)
def ani():
global e1_pos, c_pos, k_pos, e2_pos, s_pos, e1_pos_add, c_pos_add, k_pos_add, e2_pos_add, s_pos_add
e1_pos += e1_pos_add
c_pos += c_pos_add
k_pos += k_pos_add
e2_pos += e2_pos_add
s_pos += s_pos_add
print (e1_pos)
if e1_pos > 700:
e1_pos_add = -1
if c_pos > 700:
c_pos_add = -1
if k_pos > 700:
k_pos_add = -1
if e2_pos > 700:
e2_pos_add = -1
if s_pos > 700:
s_pos_add = -1
if e1_pos < 100:
e1_pos_add = 1
if c_pos < 100:
c_pos_add = 1
if k_pos < 100:
k_pos_add = 1
if e2_pos < 100:
e2_pos_add = 1
if s_pos < 100:
s_pos_add = 1
hauptcanvas.move(move_e1, 0, e1_pos_add)
hauptcanvas.move(move_c, 0, e1_pos_add)
hauptcanvas.move(move_k, 0, e1_pos_add)
hauptcanvas.move(move_e2, 0, e1_pos_add)
hauptcanvas.move(move_s, 0, e1_pos_add)
while introscreen:
ani()
#clock.tick(40)
time.sleep(0.1)
Ich möchte mir einen screen mit animierten Buchstaben basteln.
Es sollen einfach Buchstaben (Grafiken) im Bild hoch und runter laufen.
Folgendes Programm funktioniert aber nicht und ich finde den Grund nicht.
Wenn ich das über Pfeiltasten (mit bind) programmiere, läuft es, aber in einer Schleife hab ich nur noch einen weißen, eingefrorenen Bildschirm.
import time
from tkinter import *
from PIL import ImageTk, Image
main = Tk()
main.title("Test")
main.iconbitmap("prgpix/WindowIcon.ico")
main.geometry("1920x1200+0+0")
# main.wm_minsize(width=640, height=400) # wenn resizable = false, braucht man das hier ja nicht wirklich
main.resizable(width = False, height = False)
#main.configure(bg = "black")
hauptcanvas = Canvas(main, width = 1920, height = 1200, bd = 0, bg = "black", highlightthickness = 0)
hauptcanvas.place(x = 0, y = 0)
def startgedrueckt():
introscreen = False
introscreen = True
e1_pos = 200
c_pos = 250
k_pos = 300
e2_pos = 250
s_pos = 200
e1_pos_add = 1
c_pos_add = 1
k_pos_add = 1
e2_pos_add = 1
s_pos_add = 1
e_img = PhotoImage(file = "Stammtisch\Intro-E.png")
c_img = PhotoImage(file = "Stammtisch\Intro-C.png")
k_img = PhotoImage(file = "Stammtisch\Intro-K.png")
s_img = PhotoImage(file = "Stammtisch\Intro-S.png")
move_e1 = hauptcanvas.create_image(600, e1_pos, image=e_img, anchor="nw", tag="e1")
move_c = hauptcanvas.create_image(750, c_pos, image=c_img, anchor="nw", tag="c")
move_k = hauptcanvas.create_image(900, k_pos, image=k_img, anchor="nw", tag="k")
move_e2 = hauptcanvas.create_image(1050, e2_pos, image=e_img, anchor="nw", tag="e2")
move_s = hauptcanvas.create_image(1200, s_pos, image=s_img, anchor="nw", tag="s")
startbutton_img = ImageTk.PhotoImage(file="Stammtisch\STARTbutton.png")
startbutton = Button(hauptcanvas, borderwidth=0, bg="black", command=startgedrueckt)
startbutton.config(image=startbutton_img, activebackground="black")
startbutton.place(x=830, y=990)
def ani():
global e1_pos, c_pos, k_pos, e2_pos, s_pos, e1_pos_add, c_pos_add, k_pos_add, e2_pos_add, s_pos_add
e1_pos += e1_pos_add
c_pos += c_pos_add
k_pos += k_pos_add
e2_pos += e2_pos_add
s_pos += s_pos_add
print (e1_pos)
if e1_pos > 700:
e1_pos_add = -1
if c_pos > 700:
c_pos_add = -1
if k_pos > 700:
k_pos_add = -1
if e2_pos > 700:
e2_pos_add = -1
if s_pos > 700:
s_pos_add = -1
if e1_pos < 100:
e1_pos_add = 1
if c_pos < 100:
c_pos_add = 1
if k_pos < 100:
k_pos_add = 1
if e2_pos < 100:
e2_pos_add = 1
if s_pos < 100:
s_pos_add = 1
hauptcanvas.move(move_e1, 0, e1_pos_add)
hauptcanvas.move(move_c, 0, e1_pos_add)
hauptcanvas.move(move_k, 0, e1_pos_add)
hauptcanvas.move(move_e2, 0, e1_pos_add)
hauptcanvas.move(move_s, 0, e1_pos_add)
while introscreen:
ani()
#clock.tick(40)
time.sleep(0.1)