zoukankan      html  css  js  c++  java
  • 猜拳小游戏绿色版

    import random
    import tkinter as tk
    def shu():
        t.insert(tk.INSERT, '很遗憾,你输了
    ')
    def ying():
        t.insert(tk.INSERT, '恭喜你,赢了
    ')
    def ping():
        t.insert(tk.INSERT, '平局
    ')
    def jiandao():
        cpt = random.randint(0, 2)
        t.delete(0.0, tk.END)
        t.insert(tk.INSERT, '电脑为:' + data[cpt] + '
    ')
        if cpt == 0:
            shu()
        elif cpt == 1:
            ping()
        else:
            ying()
    def shitou():
        cpt = random.randint(0, 2)
        t.delete(0.0, tk.END)
        t.insert(tk.INSERT, '电脑为:' + data[cpt] + '
    ')
        if cpt == 0:
            ping()
        elif cpt == 1:
            ying()
        else:
            shu()
    def bu():
        cpt = random.randint(0, 2)
        t.delete(0.0, tk.END)
        t.insert(tk.INSERT, '电脑为:' + data[cpt] + '
    ')
        if cpt == 0:
            ying()
        elif cpt == 1:
            shu()
        else:
            ping()
    def qui():
        win.destroy()
    data = ['石头', '剪刀', '布']
    win = tk.Tk()
    win.geometry('300x300+300+300')
    win.title("剪刀石头布游戏")
    l = tk.Label(win, text='你好!欢迎来到猜拳游戏', bg='green', width=30, height=2).pack()
    t = tk.Text(win, height=3)
    t.pack()
    b1 = tk.Button(win, text='剪刀', font=('Arial', 12), width=10, height=1, command=jiandao)
    b1.pack()
    b2 = tk.Button(win, text='石头', font=('Arial', 12), width=10, height=1, command=shitou)
    b2.pack()
    b3 = tk.Button(win, text='布', font=('Arial', 12), width=10, height=1, command=bu)
    b3.pack()
    b4 = tk.Button(win, text='退出', font=('Arial', 12), width=10, height=1, command=qui)
    b4.pack()
    win.mainloop()
    if __name__ == "__main__":
        pass
    
  • 相关阅读:
    PHP中cookie和会话编程
    PHPweb应用程序开发技巧
    javascript中DOM编程
    PHP动态创建Web站点
    在IE下FLASH背景透明而在FF下不透明的解决方法
    ThinkPHP返回插入记录的id号
    PHP面向对象编程
    PHP smarty编程总结
    Linux用户权限设置
    无法载入 mcrypt 扩展,请检查 PHP 配置
  • 原文地址:https://www.cnblogs.com/xwjhyy/p/11580655.html
Copyright © 2011-2022 走看看