ich wollte letzt mal TicTacToe programmieren und habe dazu ein ähnliches Bild wie dieses:
https://www.google.com/search?q=tic+tac ... 83M:&vet=1
genommen. Dann fing ich an die Buttons mit Pack in die Felder zu ordnen. Doch ich habe bemerkt, dass ich nicht weiß,
wie ich ein Button rechts oben und links oben bzw. rechts unten und links unten platzieren kann. Aber schaut euch den Code einfach selber an
das erklärt wahrscheinlich alles.
Code: Alles auswählen
from tkinter import *
turn = 1
def f1_button():
if turn == 1:
f1.forget()
f1_status = 1
def f2_button():
if turn == 1:
f2.forget()
f2_status = 1
def f3_button():
if turn == 1:
f3.forget()
f3_status = 1
def f4_button():
if turn == 1:
f4.forget()
f4_status = 1
def f5_button():
if turn == 1:
f5.forget()
f5_status = 1
def f6_button():
if turn == 1:
f6.forget()
f6_status = 1
def f7_button():
if turn == 1:
f7.forget()
f7_status = 1
def f8_button():
if turn == 1:
f8.forget()
f8_status = 1
def f9_button():
if turn == 1:
f9.forget()
f9_status = 1
def beenden_button():
root.quit()
root = Tk()
root.title("TicTacToe")
root.geometry('500x400')
bild = PhotoImage(file='Spielfeld.gif')
label_bild = Label(image=bild)
label_bild.place(x=0, y=0, width=500, height=400)
f1 = Button(root, text="Setzen", command=f1_button)
f1.pack(padx=60, pady=10, side=LEFT)
f2 = Button(root, text="Setzen", command=f2_button)
f2.pack(padx=60, pady=10, side=RIGHT)
f3 = Button(root, text="Setzen", command=f3_button)
f3.pack(padx=60, pady=150, side=RIGHT)
f4 = Button(root, text="Setzen", command=f4_button)
f4.pack(padx=60, pady=50, side=TOP)
f5 = Button(root, text="Setzen", command=f5_button)
f4.pack(padx=10, pady=50, side=TOP)
f6 = Button(root, text="Setzen", command=f6_button)
f4.pack(padx=10, pady=50, side=BOTTOM)
f7 = Button(root, text="Setzen", command=f7_button)
f8 = Button(root, text="Setzen", command=f8_button)
f9 = Button(root, text="Setzen", command=f9_button)
beenden = Button(root, text="Beenden", command=beenden_button)
f1.pack()
f2.pack()
f3.pack()
f4.pack()
f5.pack()
f6.pack()
f7.pack()
f8.pack()
f9.pack()
beenden.pack()
root.mainloop()
Mfg Boggel