蒙蒂霍尔悖论小程序

import tkinter as tk
import random

import tkinter as tk
import random


def start():
    print(l2[0])
    print(l1)
    global win
    global win1
    win.destroy()
    win1.destroy()
    for i in range(0,3):
        if i != l2[0]-1:
            if l1[i] == 0:
                del l1[i]
                l4[0] = i
                print(l1)
                break
    del l3[l4[0]]
    print(l3)
    win = tk.Tk()
    win.title("蒙蒂霍尔悖论游戏")
    win.geometry("300x300")
    talk = "我帮你排除了一个山羊门,"
    talk2 = "你还想选择之前的门吗?"
    h1 = tk.Label(win, text=talk, width=50, height=2)
    h1.place(x=20, y=200)
    h2 = tk.Label(win, text=talk2, width=50, height=1)
    h2.place(x=20, y=230)
    host = tk.Label(win, text="ヽ(●'ω'●)ノ:", width=10, height=2)
    host.place(x=0, y=200)
    win.resizable(False, False)
    door1 = door(l3[0])
    door1.bind("", func=result1)
    door2 = door(l3[1])
    door2.bind("", func=result2)
    tk.mainloop()

def result1(a):
    global win
    win.destroy()
    b1 = " 号门"
    win2 = tk.Tk()
    win2.geometry("250x250")
    win2.title(str(l3[0]) + b1 + "后")
    if l1[0] == 1:
        talk = "你得到了奖品为车,真厉害"
    else:
        talk ="你得到的奖品为山羊,还行"
    h1 = tk.Label(win2, text=talk, width=25, height=2)
    h1.place(x=70, y=50)
    host = tk.Label(win2, text="ヽ(●´ω`●)ノ:", width=10, height=2)
    host.place(x=0, y=50)
    b1 = tk.Button(win2, text="好的owo", width=6, height=2, command=quit)
    b1.place(x=125, y=120)
    tk.mainloop()
def result2(a):
    b1 = " 号门"
    win2 = tk.Tk()
    win2.geometry("250x250")
    win2.title(str(l3[1]) + b1 + "后")
    if l1[1] == 1:
        talk = "你得到了奖品为车,真厉害"
    else:
        talk = "你得到的奖品为山羊,也还行"
    h1 = tk.Label(win2, text=talk, width=25, height=2)
    h1.place(x=70, y=50)
    host = tk.Label(win2, text="ヽ(●´ω`●)ノ:", width=10, height=2)
    host.place(x=0, y=50)
    b1 = tk.Button(win2, text="好的owo", width=6, height=2, command=quit)
    b1.place(x=125, y=120)
    tk.mainloop()

def indoor(a):
    global win1
    a1 = a.widget["text"]
    b1 = " 号门"
    for j in a1:
        if j in b1:
            a1 = a1.replace(j, "")
    l2[0] = int(a1)
    win1 = tk.Tk()
    win1.title(str(a1) + b1)
    win1.geometry("250x250")
    host1 = tk.Label(win1, text="(—w—):你真的想选这个门吗?", width=30, height=2)
    host1.place(x=20, y=80)
    b1 = tk.Button(win1, text="是的", width=6, height=2, command=start)
    b1.place(x=40, y=120)
    b2 = tk.Button(win1, text="我再想想", width=6, height=2, command=win1.destroy)

    b2.place(x=120, y=120)

    tk.mainloop()

def door(a):
    b = " 号门"
    Door = tk.Button(win, text=str(a) + b, width=6, height=7)
    Door.place(x=10+((a-1)*120), y=40)
    return Door

win1 = 0
l1 = [0, 0, 0]
l3 = [1, 2, 3]
l2 = [0]
l4 = [0]
a2 = random.randrange(0,3)
l1[a2] = 1
win = tk.Tk()
win.title("蒙蒂霍尔悖论游戏")
win.geometry("300x300")
talk = "门后会有羊或车,请随意选择一个门~"
h1 = tk.Label(win, text=talk, width=50, height=2)
h1.place(x=20,y=200)
host = tk.Label(win, text="ヽ(●´ω`●)ノ:", width=10, height=2)
host.place(x=0, y=200)
win.resizable(False, False)
door1 = door(1)
door2 = door(2)
door3 = door(3)
door1.bind("", func=indoor)
door2.bind("", func=indoor)
door3.bind("", func=indoor)
tk.mainloop()

效果如下:

蒙蒂霍尔悖论小程序_第1张图片蒙蒂霍尔悖论小程序_第2张图片蒙蒂霍尔悖论小程序_第3张图片蒙蒂霍尔悖论小程序_第4张图片

你可能感兴趣的:(蒙蒂霍尔悖论小程序)