Ich weiß nicht, ob ich hier in der Rubrik "Allgemeine Fragen" richtig bin...
Folgendes Problem:
Eigentlich sollte sich die blaue hintergrundeinfärbung beim betätigen der nach-unten Taste der Tastatur um einen rectangle nach unten verschieben, das funktioniert aber irgendwie nicht. vielleicht könntre mir jemand weiterhelfen...
Hier der Code:
Code: Alles auswählen
from tkinter import *
import tkinter
from pynput.keyboard import Key, Listener
color=["nix", "#5882FA", "#F6CECE", "#F6CECE", "#F6CECE", "#F6CECE", "#F6CECE"]
global color1str
global color2str
global color3str
global color4str
global color5str
global color6str
global pos
pos=1
def down(state):
if state==1:
print(pos)
if pos==1:
color6str="#F6CECE"
color1str="#5882FA"
if pos==2:
color1str="#F6CECE"
color2str="#5882FA"
if pos==3:
color2str="#F6CECE"
color3str="#5882FA"
if pos==4:
color3str="#F6CECE"
color4str="#5882FA"
if pos==5:
color4str="#F6CECE"
color5str="#5882FA"
if pos==6:
color5str="#F6CECE"
color6str="#5882FA"
pos=0
pos=pos+1
def key(event):
"""shows key or tk code for the key"""
if event.keysym == 'Escape':
root.destroy()
if event.keysym == "Down":
down(1)
if event.keysym == "Right":
print(color)
elif len(event.char) == 1:
# charcters like []/.,><#$ also Return and ctrl/key
print( 'Punctuation Key %r (%r)' % (event.keysym, event.char) )
else:
# f1 to f12, shift keys, caps lock, Home, End, Delete ...
print( 'Special Key %r' % event.keysym )
root=Tk()
root.geometry("300x800")
root.overrideredirect(True)
#root.configure(background="blue")
canvas = Canvas(root, width=300, height=800, background="grey")
canvas.pack()
button1 = canvas.create_rectangle(0, 650, 300, 750, fill="#5882FA", width=2)
button2 = canvas.create_rectangle(0, 550, 300, 650, fill="#F6CECE", width=2)
button3 = canvas.create_rectangle(0, 450, 300, 550, fill="#F6CECE", width=2)
button4 = canvas.create_rectangle(0, 350, 300, 450, fill="#F6CECE", width=2)
button5 = canvas.create_rectangle(0, 250, 300, 350, fill="#F6CECE", width=2)
button6 = canvas.create_rectangle(0, 150, 300, 250, fill="#F6CECE", width=2)
canvas.create_text(150, 100, font="Arial,70", text="HOME")
canvas.create_text(150, 700, font="Arial,70", text="TV")
canvas.create_text(150, 600, font="Arial,70", text="Aufnahmen")
canvas.create_text(150, 500, font="Arial,70", text="YouTube")
canvas.create_text(150, 400, font="Arial,70", text="Spiel: Super Mario 64")
canvas.create_text(150, 300, font="Arial,70", text="Spiel: Tetris Worlds")
canvas.create_text(150, 200, font="Arial,70", text="", width=2)
#color1str=color[1]
#color2str=(color[2])
#color3str=(color[3])
#color4str=color[4]
#color5str=color[5]
#color6str=color[6]
canvas.itemconfig(button1, fill=color1str)
print (color1str)
canvas.itemconfig(button2, fill=color2str)
canvas.itemconfig(button3, fill=color3str)
canvas.itemconfig(button4, fill=color4str)
canvas.itemconfig(button5, fill=color5str)
canvas.itemconfig(button6, fill=color6str)
root.bind_all('<Key>', key)
root.mainloop()