Advertisement
paroxlp

Python tkinter variable

Apr 1st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. Hey,
  2. ich brauche Hilfe, dabei die Felder (feld1, feld2 ...) mit einem [index] zusammen zufassen.
  3. Damit ich eben nicht alles einzeln aufschreiben muss.
  4.  
  5. Thanks!
  6.  
  7.  
  8.  
  9. import tkinter as tk
  10. from tkinter import *
  11.  
  12. modul = tk.Tk()
  13. modul.geometry("900x900")
  14. modul.title("Bunt3x3")
  15. modul.resizable(width=False, height=False)
  16.  
  17.  
  18. r = "red"
  19. y = "yellow"
  20. g = "green"
  21. b = "blue"
  22. def change():
  23.     if feld1["bg"] == r:
  24.         feld1.config(bg=g)
  25.         feld3.config(bg=g)
  26.         feld5.config(bg=g)
  27.         feld7.config(bg=g)
  28.  
  29.         feld2.config(bg=b)
  30.         feld4.config(bg=b)
  31.         feld6.config(bg=b)
  32.         feld8.config(bg=b)
  33.  
  34.         feldlabel.config(text="Rot & gelb")
  35.     elif feld1["bg"] == g:
  36.         feld1.config(bg=r)
  37.         feld3.config(bg=r)
  38.         feld5.config(bg=r)
  39.         feld7.config(bg=r)
  40.  
  41.         feld2.config(bg=y)
  42.         feld4.config(bg=y)
  43.         feld6.config(bg=y)
  44.         feld8.config(bg=y)
  45.  
  46.         feldlabel.config(text="Gruen & blau")
  47.  
  48. feld1 = tk.Frame(bg =r, width = 300, height = 300)
  49. feld1.grid(column=1, row = 1)
  50. feld3 = tk.Frame(bg =r, width = 300, height = 300)
  51. feld3.grid(column=3, row = 1)
  52. feld5 = tk.Frame(bg =r, width = 300, height = 300)
  53. feld5.grid(column=1, row = 3)
  54. feld7 = tk.Frame(bg =r, width = 300, height = 300)
  55. feld7.grid(column=3, row = 3)
  56. feld2 = tk.Frame(bg =y, width = 300, height = 300)
  57. feld2.grid(column=2, row = 1)
  58. feld4 = tk.Frame(bg =y, width = 300, height = 300)
  59. feld4.grid(column=1, row = 2)
  60. feld6 = tk.Frame(bg =y, width = 300, height = 300)
  61. feld6.grid(column=3, row = 2)
  62. feld8 = tk.Frame(bg =y, width = 300, height = 300)
  63. feld8.grid(column=2, row = 3)
  64.  
  65. feld = tk.Frame(bg = "white", width = 300, height = 300).grid(column = 2, row=2)
  66. feldlabel = tk.Label(text = "Gruen & blau",bg = "white", fg = "black", font=("Arial",15,"bold"))
  67. feldlabel.grid(column=2,row=2)
  68. feldbutton = tk.Button(text = "Farbe aendern!", font=("Arial",15,"bold"), bg = "white", fg = "black", command = change).place(x = 370, y = 470)
  69. modul.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement