Label verschwindet
Verfasst: Dienstag 3. August 2021, 19:03
Hallo zusammen,
ich lerne grad etwas TKinker und habe ein kleines Problemchen.
Das Fenster zeigt alles richtig an, aber wenn ich das Fenster außerhalb der Bildschirms verschiebe, verschwinden die Labels und werden durch graue
Labels ersetzt und dann steht dort in der Mitte "grey"
Weiß jemand woran das liegt?
VG
Hier ist der Code:
class Volley_field_label(tk.Label):
def __init__(self, parent, **kwargs):
# Defaults
kwargs['text'] = 'grey'
super().__init__(parent, **kwargs)
self.canvas = Canvas(self, width=450, height=400, background='white')
self.coordinates = [60, 150, 210, 50, 150, 210, 50, 150, 210]
self.initUI()
def initUI(self):
'''
self.master.title("Lines")
self.pack(fill=BOTH, expand=1)
canvas = Canvas(self)
canvas.create_line(15, 25, 200, 25)
canvas.create_line(300, 35, 300, 200, dash=(4, 2))
canvas.create_line(55, 85, 155, 85, 105, 180, 55, 85)
canvas.pack(fill=BOTH, expand=1)
'''
self.canvas.grid(row=1,column=0, columnspan=5)
self.canvas.create_line(120, 20, 120, 360, dash=(4, 2))
self.canvas.create_line(180, 20, 180, 360, dash=(4, 2))
self.canvas.create_line(60, 80, 240, 80, dash=(4, 2))
self.canvas.create_line(60, 310, 240, 310, dash=(4, 2))
self.canvas.create_rectangle(60, 20, 240, 360)
self.canvas.create_rectangle(60, 140, 240, 260)
self.canvas.create_line(30, 200, 270, 200 )
self.canvas.create_line(300, 100, 420, 100 )
self.canvas.create_line(340, 70, 340, 130 )
self.canvas.create_line(380, 70, 380, 130 )
self.canvas.create_line(300, 230, 420, 230 )
self.canvas.create_line(340, 200, 340, 260 )
self.canvas.create_line(380, 200, 380, 260 )
def draw_arrow(self, start_position, end_position_field, rating):
start_x = self.get_start_coordinates_x(start_position)
start_y = 210
end_x = self.get_end_coordinates_x(end_position_field)
end_y = self.get_end_coordinates_y(end_position_field)
print(start_x)
print(start_y)
print(end_x)
print(end_y)
self.canvas.create_line(start_x, start_y, end_x, end_y, arrow=tk.LAST)
def get_start_coordinates_x(self, position):
switcher = {
4:70,
3:120,
2:150
}
return switcher.get(position)
def get_end_coordinates_x(self, position):
position = position - 1
self.coordinates[position] = self.coordinates[position] + 7
return self.coordinates[position]
def get_end_coordinates_y(self, position):
switcher = {
1:50,
2:50,
3:50,
4:100,
5:100,
6:100,
7:160,
8:160,
9:160
}
return switcher.get(position)
Main:
from VolleyballField import *
import tkinter as tk
from tkinter import *
root = Tk()
e = Entry(root, width=50)
myLabel2 = Volley_field_label(root)
myLabel3 = Volley_field_label(root)
myLabel4 = Volley_field_label(root)
myLabel3.draw_arrow(4,1, "+")
myLabel3.draw_arrow(4,1, "+")
myLabel3.draw_arrow(4,6, "+")
myLabel3.draw_arrow(4,6, "+")
myLabel2.grid(row=1, column=1)
myLabel3.grid(row=1, column=2)
myLabel4.grid(row=2, column=1)
e.grid(row=2, column=2)
root.mainloop()
ich lerne grad etwas TKinker und habe ein kleines Problemchen.
Das Fenster zeigt alles richtig an, aber wenn ich das Fenster außerhalb der Bildschirms verschiebe, verschwinden die Labels und werden durch graue
Labels ersetzt und dann steht dort in der Mitte "grey"
Weiß jemand woran das liegt?
VG
Hier ist der Code:
class Volley_field_label(tk.Label):
def __init__(self, parent, **kwargs):
# Defaults
kwargs['text'] = 'grey'
super().__init__(parent, **kwargs)
self.canvas = Canvas(self, width=450, height=400, background='white')
self.coordinates = [60, 150, 210, 50, 150, 210, 50, 150, 210]
self.initUI()
def initUI(self):
'''
self.master.title("Lines")
self.pack(fill=BOTH, expand=1)
canvas = Canvas(self)
canvas.create_line(15, 25, 200, 25)
canvas.create_line(300, 35, 300, 200, dash=(4, 2))
canvas.create_line(55, 85, 155, 85, 105, 180, 55, 85)
canvas.pack(fill=BOTH, expand=1)
'''
self.canvas.grid(row=1,column=0, columnspan=5)
self.canvas.create_line(120, 20, 120, 360, dash=(4, 2))
self.canvas.create_line(180, 20, 180, 360, dash=(4, 2))
self.canvas.create_line(60, 80, 240, 80, dash=(4, 2))
self.canvas.create_line(60, 310, 240, 310, dash=(4, 2))
self.canvas.create_rectangle(60, 20, 240, 360)
self.canvas.create_rectangle(60, 140, 240, 260)
self.canvas.create_line(30, 200, 270, 200 )
self.canvas.create_line(300, 100, 420, 100 )
self.canvas.create_line(340, 70, 340, 130 )
self.canvas.create_line(380, 70, 380, 130 )
self.canvas.create_line(300, 230, 420, 230 )
self.canvas.create_line(340, 200, 340, 260 )
self.canvas.create_line(380, 200, 380, 260 )
def draw_arrow(self, start_position, end_position_field, rating):
start_x = self.get_start_coordinates_x(start_position)
start_y = 210
end_x = self.get_end_coordinates_x(end_position_field)
end_y = self.get_end_coordinates_y(end_position_field)
print(start_x)
print(start_y)
print(end_x)
print(end_y)
self.canvas.create_line(start_x, start_y, end_x, end_y, arrow=tk.LAST)
def get_start_coordinates_x(self, position):
switcher = {
4:70,
3:120,
2:150
}
return switcher.get(position)
def get_end_coordinates_x(self, position):
position = position - 1
self.coordinates[position] = self.coordinates[position] + 7
return self.coordinates[position]
def get_end_coordinates_y(self, position):
switcher = {
1:50,
2:50,
3:50,
4:100,
5:100,
6:100,
7:160,
8:160,
9:160
}
return switcher.get(position)
Main:
from VolleyballField import *
import tkinter as tk
from tkinter import *
root = Tk()
e = Entry(root, width=50)
myLabel2 = Volley_field_label(root)
myLabel3 = Volley_field_label(root)
myLabel4 = Volley_field_label(root)
myLabel3.draw_arrow(4,1, "+")
myLabel3.draw_arrow(4,1, "+")
myLabel3.draw_arrow(4,6, "+")
myLabel3.draw_arrow(4,6, "+")
myLabel2.grid(row=1, column=1)
myLabel3.grid(row=1, column=2)
myLabel4.grid(row=2, column=1)
e.grid(row=2, column=2)
root.mainloop()