骷髏坑人小技巧1[python]:坑爹遊戲[tkinter]

骷髏解說發表於2020-12-21
from tkinter import *
t = Tk()

from random import randint as randnum

click_n = 0

t.title("坑爹小遊戲")
t.geometry('800x800')

b = Button(t,text='點選我獲得1000萬',command=lambda: get_c)
b.pack()

a = Button(t,text='如果按鈕不見了,那麼點我,就可以再次隨機移動。',command=lambda:c2)
a.pack()

def c1(pos):
    xi = randnum(1,1000)
    yi = randnum(1,1000)
    b.place(x=xi,y=yi)

def c2():
    xi = randnum(1,1000)
    yi = randnum(1,1000)
    b.place(x=xi,y=yi)

def get_c():
    global click_n  
    click_n += 1
    print('又點到了一次!好厲害!你點到了'+click_n+'次!!!')

t.bind('<Enter>',c1)
t.mainloop()

相關文章