生活随笔
收集整理的這篇文章主要介紹了
Python实现九宫格解锁
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
實現的基礎。9個點,9個圓,畫線。全局變量的賦值及調用函數改變全局變量的值。? global s1global s2global c1c1 = 0def xsq(a, b, c):global s1s1 = aglobal s2s2 = b ?
這里設置的密碼是Z字解鎖。下圖中的C1變量為解鎖需要的值。改變C1的值,即可以改變解鎖需要的圖案。如果你需要改變密碼,你需要改變C1的值,9個點對應的值為1-9。你點擊的點圖案加起來為C1的值即可解鎖。 def xsq(a, b, c):global s1s1 = aglobal s2s2 = bglobal c1c1 = c1 + cif c1 == 35:rt.destroy() ?
以下是完整代碼 rt = Tk()rt.title('解鎖')rt.geometry('300x300+200+100')lb = Label(rt, text='繪制圓', width=30, height=2)lb.place(x=50, y=10)global s1global s2global c1c1 = 0def xsq(a, b, c):global s1s1 = aglobal s2s2 = bglobal c1c1 = c1 + cif c1 == 35:rt.destroy()def cov1():s1 = 35s2 = 35c = 1xsq(s1, s2, c)def cov2():s3 = 150s4 = 35ln2 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)c = 2xsq(s3, s4, c)def cov3():s3 = 260s4 = 35ln3 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)c = 3xsq(s3, s4, c)def cov4():s3 = 35s4 = 135ln4 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)c = 4xsq(s3, s4, c)def cov5():s3 = 150s4 = 135ln5 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)c = 5xsq(s3, s4, c)def cov6():s3 = 260s4 = 135ln6 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)c = 6xsq(s3, s4, c)def cov7():s3 = 35s4 = 235ln7 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)c = 7xsq(s3, s4, c)def cov8():s3 = 150s4 = 235ln8 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)c = 8xsq(s3, s4, c)def cov9():s3 = 260s4 = 235ln9 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)c = 9xsq(s3, s4, c)cv = Canvas(rt, bg='#cccccc', width=500, height=500)button1 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov1)button1.place(x=25, y=25)button2 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov2)button2.place(x=140, y=25)button3 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov3)button3.place(x=255, y=25)button4 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov4)button4.place(x=25, y=125)button5 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov5)button5.place(x=140, y=125)button6 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov6)button6.place(x=255, y=125)button7 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov7)button7.place(x=25, y=225)button8 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov8)button8.place(x=140, y=225)button9 = tkinter.Button(rt, text='', bg='red', width=2, height=1, command=cov9)button9.place(x=255, y=225)ov1 = cv.create_oval((10, 10, 60, 60), fill='red', width=5, outline='yellow', dash=(5, 2))ov2 = cv.create_oval((125, 10, 175, 60), fill='red', width=5, outline='yellow', dash=(5, 2))ov3 = cv.create_oval((240, 10, 290, 60), fill='red', width=5, outline='yellow', dash=(5, 2))ov4 = cv.create_oval((125, 110, 175, 160), fill='red', width=5, outline='yellow', dash=(5, 2))ov5 = cv.create_oval((10, 110, 60, 160), fill='red', width=5, outline='yellow', dash=(5, 2))ov6 = cv.create_oval((240, 110, 290, 160), fill='red', width=5, outline='yellow', dash=(5, 2))ov7 = cv.create_oval((125, 210, 175, 260), fill='red', width=5, outline='yellow', dash=(5, 2))ov8 = cv.create_oval((10, 210, 60, 260), fill='red', width=5, outline='yellow', dash=(5, 2))ov9 = cv.create_oval((240, 210, 290, 260), fill='red', width=5, outline='yellow', dash=(5, 2))def ass3():rt.destroy()bt10= Button(rt, text='返回上一級', width=45, height=1, command=ass3)bt10.place(x=0, y=270)cv.place(x=0, y=0)rt.mainloop()
總結
以上是生活随笔為你收集整理的Python实现九宫格解锁的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。