欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python实现九宫格解锁

程序员文章站 2022-05-24 23:35:47
实现的基础。9个点,9个圆,画线。以下是完整代码rt = Tk() rt.title('解锁') rt.geometry('300x300+200+100') lb = Label(rt, text='绘制圆', width=30, height=2) lb.place(x=50, y=10) global s1 global s2 global c1 c1 = 0 def xsq(a, b, c):...
  1. 实现的基础。
  2. 9个点,9个圆,画线。
  3. 全局变量的赋值及调用函数改变全局变量的值。
  4.  
     global s1
        global s2
        global c1
        c1 = 0
    
        def xsq(a, b, c):
            global s1
            s1 = a
            global s2
            s2 = b

     

  5. 这里设置的密码是Z字解锁。下图中的C1变量为解锁需要的值。改变C1的值,即可以改变解锁需要的图案。
  6. 如果你需要改变密码,你需要改变C1的值,9个点对应的值为1-9。你点击的点图案加起来为C1的值即可解锁。
  7. def xsq(a, b, c):
            global s1
            s1 = a
            global s2
            s2 = b
            global c1
            c1 = c1 + c
            if c1 == 35:
                rt.destroy()

     

  8. 以下是完整代码
  9. rt = Tk()
        rt.title('解锁')
        rt.geometry('300x300+200+100')
        lb = Label(rt, text='绘制圆', width=30, height=2)
        lb.place(x=50, y=10)
        global s1
        global s2
        global c1
        c1 = 0
    
        def xsq(a, b, c):
            global s1
            s1 = a
            global s2
            s2 = b
            global c1
            c1 = c1 + c
            if c1 == 35:
                rt.destroy()
    
        def cov1():
            s1 = 35
            s2 = 35
            c = 1
            xsq(s1, s2, c)
    
        def cov2():
            s3 = 150
            s4 = 35
            ln2 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)
            c = 2
            xsq(s3, s4, c)
    
        def cov3():
            s3 = 260
            s4 = 35
            ln3 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)
            c = 3
            xsq(s3, s4, c)
    
        def cov4():
            s3 = 35
            s4 = 135
            ln4 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)
            c = 4
            xsq(s3, s4, c)
    
        def cov5():
            s3 = 150
            s4 = 135
            ln5 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)
            c = 5
            xsq(s3, s4, c)
    
        def cov6():
            s3 = 260
            s4 = 135
            ln6 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)
            c = 6
            xsq(s3, s4, c)
    
        def cov7():
            s3 = 35
            s4 = 235
            ln7 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)
            c = 7
            xsq(s3, s4, c)
    
        def cov8():
            s3 = 150
            s4 = 235
            ln8 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)
            c = 8
            xsq(s3, s4, c)
    
        def cov9():
            s3 = 260
            s4 = 235
            ln9 = cv.create_line(s1, s2, s3, s4, fill='blue', arrowshape=(20, 20, 10), width=5)
            c = 9
            xsq(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实现九宫格解锁

本文地址:https://blog.csdn.net/qq_48288251/article/details/107038528