Найти - Пользователи
Полная версия: .
Начало » GUI » .
1
Ilya
.
Singularity
#Tic-tac-toe
from tkinter import *
import tkinter.messagebox
def question():
    child = Toplevel(root)
    child.title('Question')
    child.geometry('400x250+400+300')
    def output(event):
        s = ent.get()
        if s == "1970":
          but1=Button(child,text= "You're right!")
          but1.grid(row=2,column=0)
          but1.bind("<Button-1>",click())
    ent = Entry(child,width=40)
    but = Button(child,text="When was Lenin born?")
    ent.grid(row=0,column=0,padx=20)
    but.grid(row=1,column=0)
    but.bind("<Button-1>",output)
    root.mainloop()
#exit
def exit_(event):
    root.destroy()
#help
def help(event):
    tkinter.messagebox.showinfo("Справка по игре.",
                                "F1 - Информация.\n"+
                                "F12 - Новая игра.\n"+
                                "Ecs - выход из игры.\n")
#begin one more time
def begin(event):
    global butn
    global field
    global numButton
    knopki()
    field = [0, 0, 0, 0, 0, 0, 0, 0, 0]
    numButton = []
#the logic og game
def logik():
    global field
    global numButton
    end = False
    if field[0] == field[1] == field[2] > 0:
            winner = field[0]
            end = True
    elif field[3] == field[4] == field[5] > 0:
            winner = field[3]
            end = True
    elif field[6] == field[7] == field[8] > 0:
            winner = field[6]
            end = True
    elif field[0] == field[3] == field[6] > 0:
            winner = field[0]
            end = True
    elif field[1] == field[4] == field[7] > 0:
            winner = field[1]
            end = True
    elif field[2] == field[5] == field[8] > 0:
            winner = field[2]
            end = True
    elif field[0] == field[4] == field[8] > 0:
            winner = field[0]
            end = True
    elif field[2] == field[4] == field[6] > 0:
            winner = field[2]
            end = True
    else:
            if len(numButton) == 9:
                    tkinter.messagebox.showinfo("The end!", "  Draw!  ")
    if end:
            if winner == 1:
                user = "Tic"
            elif winner == 2:
                user = "Tac"
            tkinter.messagebox.showinfo("The end", "The winner- " + user)
            begin(None)
def click(button, num):
    global numButton
    if num not in numButton:
        global XO
        if XO == 1:
            button.config(text = 'Tic')
            button.config(bg = 'gold')
            field[num] = XO
            XO = 2
        else:
            button.config(text = 'Tac')
            button.config(bg = 'grey')
            field[num] = XO
            XO = 1
        numButton.append(num)
        logik()
field = [0, 0, 0, 0, 0, 0, 0, 0, 0]
XO = 1
numButton = []
root = Tk()
root.title("Tic-tac-toe")
root.geometry("342x345")
root.resizable(False, False)
def btns():
#0
    ris0 = Button(root, width=13, height=5, bg="green",
              text="history", command=lambda:click(ris0, 0))
    ris0.grid(row = 1, column = 1)
#1
    ris1 = Button(root, width=13, height=5, bg="green",
              text="art", command=lambda:click(ris1, 1))
    ris1.grid(row = 1, column = 2)
#2
    ris2 = Button(root, width=13, height=5, bg="green",
              text="science", command=lambda:click(ris2, 2))
    ris2.grid(row = 1, column = 3)
#3
    ris3 = Button(root, width=13, height=5, bg="green",
              text="sport", command=lambda:click(ris3, 3))
    ris3.grid(row = 2, column = 1)
#4
    ris4 = Button(root, width=13, height=5, bg="green",
              text="Difficult question", command=lambda:click(ris4, 4))
    ris4.grid(row = 2, column = 2)
#5
    ris5 = Button(root, width=13, height=5, bg="green",
              text="study of local lore", command=lambda:click(ris5, 5))
    ris5.grid(row = 2, column = 3)
#6
    ris6 = Button(root, width=13, height=5, bg="green",
              text="eography", command=lambda:click(ris6, 6))
    ris6.grid(row = 3, column = 1)
#7
    ris7 = Button(root, width=13, height=5, bg="green",
              text="music", command=lambda:click(ris7, 7))
    ris7.grid(row =3, column = 2)
#8
    ris8 = Button(root, width=13, height=5, bg="green",
              text="literature", command=lambda:click(ris8, 8))
    ris8.grid(row = 3, column = 3)
    butn = [ris0, ris1, ris2, ris3, ris4, ris5, ris6, ris7, ris8]
btns()
#functional buttons
root.bind('<Escape>', exit_)
root.bind('<F1>', help)
root.bind('<F12>', begin)
root.mainloop()
Ilya
.
4kpt_II
Мамочка моя…
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB