首页 > 其他分享 >4.17

4.17

时间:2024-06-14 19:58:59浏览次数:8  
标签:4.17 30 40 button2 num place 100

【题目描述】设计一个电子算盘。要求绘制电子算盘界面,设计并实现打珠算过程(界面参考如下图示)。

界面右侧要求以图形绘制的方式绘制自画像,注意不能是图像文件显示的形式。


图片1.png

from tkinter import *

tk = Tk()

tk.title("电子算盘")  # 窗口名称

tank = Canvas(tk, width=1000, height=600, bg='ivory')  # 创建画板

tank.pack()  # 显示画板

tank.create_rectangle(30, 30, 520, 190, width=3)  # 左上侧方框

tank.create_rectangle(30, 190, 520, 570, width=3)  # 左下侧方框

tank.create_oval(900, 400, 620, 120, fill='yellow')

tank.create_oval(800, 200, 850, 250, fill='black', tags='left')

tank.create_oval(670, 200, 720, 250, fill='black', tags='right')

tank.create_line(695, 320, 825, 320, width=5, tags='mouth')

backround_image = PhotoImage(file="img.png")  # 上珠图片

backround_image2 = PhotoImage(file="img_1.png")  # 下珠图片

button = Button()

button1 = [button for i in range(5)]  # 5个上珠

button2 = [[button for i in range(5)] for i in range(4)]  # 四行,每行五个下珠

num = [[0 for i in range(5)] for i in range(4)]  # 五个下珠分别对应的数值

num2 = [0 for i in range(5)]  # 五个上珠分别对应的数值

def getNum(num, num2):  # 计算算盘总和

    sum_ = 0

    for i in num:

        for j in i:

            sum_ += j

    for i in num2:

        sum_ += i

    return sum_

def button_click_back(events):  # 鼠标右击点击事件触发

    widget = events.widget

    for i in range(5):

        if widget == button1[i]:

            button1[i].place(x=40 + 100 * i, y=50 + 70 * 1)

            num2[i] = 0

            label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

            label.place(x=780, y=30)

    for i in range(4):

        for j in range(5):

            if widget == button2[i][j]:

                if i == 3:

                    button2[3][j].place(x=40 + 100 * j, y=210 + 70 * (i + 1))

                    num[3][j] = 0

                    label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

                    label.place(x=780, y=30)

                if i == 2:

                    button2[2][j].place(x=40 + 100 * j, y=210 + 70 * (i + 1))

                    button2[3][j].place(x=40 + 100 * j, y=210 + 70 * (i + 2))

                    num[2][j] = 0

                    num[3][j] = 0

                    label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

                    label.place(x=780, y=30)

                if i == 1:

                    button2[1][j].place(x=40 + 100 * j, y=210 + 70 * (i + 1))

                    button2[2][j].place(x=40 + 100 * j, y=210 + 70 * (i + 2))

                    button2[3][j].place(x=40 + 100 * j, y=210 + 70 * (i + 3))

                    num[1][j] = 0

                    num[2][j] = 0

                    num[3][j] = 0

                    label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

                    label.place(x=780, y=30)

                if i == 0:

                    button2[0][j].place(x=40 + 100 * j, y=210 + 70 * (i + 1))

                    button2[1][j].place(x=40 + 100 * j, y=210 + 70 * (i + 2))

                    button2[2][j].place(x=40 + 100 * j, y=210 + 70 * (i + 3))

                    button2[3][j].place(x=40 + 100 * j, y=210 + 70 * (i + 4))

                    num[0][j] = 0

                    num[1][j] = 0

                    num[2][j] = 0

                    num[3][j] = 0

                    label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

                    label.place(x=780, y=30)

def button_click(events):  # 鼠标左击点击事件触发

    widget = events.widget

    for i in range(5):

        if widget == button1[i]:

            button1[i].place(x=40 + 100 * i, y=50 + 70 * 0)

            num2[i] = 10 ** (4 - i) * 5

            label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

            label.place(x=780, y=30)

    for i in range(4):

        for j in range(5):

            if widget == button2[i][j]:

                if i == 3:

                    button2[0][j].place(x=40 + 100 * j, y=210 + 70 * (i - 3))

                    button2[1][j].place(x=40 + 100 * j, y=210 + 70 * (i - 2))

                    button2[2][j].place(x=40 + 100 * j, y=210 + 70 * (i - 1))

                    button2[3][j].place(x=40 + 100 * j, y=210 + 70 * (i))

                    num[0][j] = 10 ** (4 - j) * 1

                    num[1][j] = 10 ** (4 - j) * 1

                    num[2][j] = 10 ** (4 - j) * 1

                    num[3][j] = 10 ** (4 - j) * 1

                    label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

                    label.place(x=780, y=30)

                if i == 2:

                    button2[0][j].place(x=40 + 100 * j, y=210)

                    button2[1][j].place(x=40 + 100 * j, y=210 + 70 * 1)

                    button2[2][j].place(x=40 + 100 * j, y=210 + 70 * 2)

                    num[0][j] = 10 ** (4 - j) * 1

                    num[1][j] = 10 ** (4 - j) * 1

                    num[2][j] = 10 ** (4 - j) * 1

                    label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

                    label.place(x=780, y=30)

                if i == 1:

                    button2[0][j].place(x=40 + 100 * j, y=210)

                    button2[1][j].place(x=40 + 100 * j, y=210 + 70 * 1)

                    num[0][j] = 10 ** (4 - j) * 1

                    num[1][j] = 10 ** (4 - j) * 1

                    label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

                    label.place(x=780, y=30)

                else:

                    button2[i][j].place(x=40 + 100 * j, y=210 + 70 * i)

                    num[0][j] = 10 ** (4 - j) * 1

                    label = Label(tk, text="当前数字:" + str(getNum(num, num2)), width=30, height=4)

                    label.place(x=780, y=30)

for i in range(5):  # 生成5个上珠

    button1[i] = Button(tk, image=backround_image)

    button1[i].bind("<Button-1>", button_click)

    button1[i].bind("<Button-3>", button_click_back)

    button1[i]["bg"] = "ivory"

    button1[i]["border"] = "0"

    button1[i].place(x=40 + 100 * i, y=50 + 70)

for i in range(4):  # 四行,每行生成5个下珠

    for j in range(5):

        button2[i][j] = Button(tk, image=backround_image2)

        button2[i][j].bind("<Button-1>", button_click)

        button2[i][j].bind("<Button-3>", button_click_back)

        button2[i][j]["bg"] = "ivory"

        button2[i][j]["border"] = "0"

        button2[i][j].place(x=40 + 100 * j, y=210 + 70 * (i + 1))

tk.mainloop()

标签:4.17,30,40,button2,num,place,100
From: https://www.cnblogs.com/gjsgjs/p/18248535

相关文章

  • 4.17
    中国大学排名爬取 importrequestsfrombs4importBeautifulSoupasbsimportpandasaspdfrommatplotlibimportpyplotaspltdefget_rank(url):count=0rank=[]headers={"user-agent":"Mozilla/5.0(WindowsNT10.0;Win64;x64)App......
  • 4.16-4.17技术支持面试
    1、讲讲你的实习经历xxx2、讲讲密码学,对称和非对称(公钥加密)的区别,非对称是否可以用私钥加密;对称和非对称区别在于,对称使用同一个密钥加密解密(有安全隐患),非对称是公钥加密私钥解密(私钥一般储存在服务器);可行,应用于数字签名方面可以,私钥加密公钥验证解密签名,但是数字签名的过程包......
  • 4.17思凡特面试
    hive语法重视hdfs调优怎么编写清洗怎么写支持压缩的map中间结果一些误区  datanode接受数据是一个块一个块往上传,后面两个节点是依次调用的元数据得在namenode内存中加载,而非仅存在磁盘上Fsimage保存目录和iNode,eidts记录更新操作两个并不是一致的,第一......
  • 2024.04.17
        学习时间1h代码行数50行博客量2篇学习内容主要进行了《从小工到大工》的阅读,并且对代码进行了优化  <template><viewclass="index"><index-headerbgColor="bg-index-header"@headerSwitch="headerSwitch"/>......
  • 4.17
    地铁主界面<%--CreatedbyIntelliJIDEA.User:席酒Date:2024/4/30Time:15:53TochangethistemplateuseFile|Settings|FileTemplates.--%><%@pagecontentType="text/html;charset=UTF-8"language="java"%><......
  • 4.17
    SQLite的优点主要有以下几个:简单易用:SQLite非常易于安装和使用,只需要引入单个库文件,便可以开始使用它提供的API进行开发。小巧灵活:由于SQLite的设计目标定位为轻量级的数据库管理系统,因此它的库文件非常小巧,适合在嵌入式设备和移动终端中使用。零配置:SQLite不需要任何专门的配置或......
  • 4.17训练赛
    感觉就是,题并没有多难,但考场上就是想不出来。链接:https://vjudge.net/contest/622884#problem/B 天杀的B题,计算重心,真没想到要使得重心尽可能的低,在竖立的时候是不需要考虑的,主要需要考虑水平方向上的,也就是水瓶在空中横置的时候,这时候就需要用到力矩了。 C就是在一个......
  • 4.17毕设
    今天做了一个分页,app的分页和web端不太一样,点击下一页按钮并不会触发一个方法,而是通过内置的一个监测,确定用户是点击前一页还是后一页,以及变化之后的页码,再将全部查询到的内容按照页面要求封装。还做了一个上传图片并识别的功能,明天把之前的饮食情况查询出来,   ......
  • 4.17
    趣味典故通过不同的短篇传统典故,让儿童学习更多的常用字词及歇后语等。充分理解文字背后的故事和含义。在学习过程中塑造符合社会主流要求的观念。将不同典故设计为不同关卡,根据字数及词语的难易程度分级。在关卡中,在故事的部分句子内制作填空题,让用户根据理解选择正确的字或词......
  • 2024.4.17python复习
    非0整数(正数、负数)进行bool转换,均为true。0的强制类型转换为bool为falsebool强制类型,如果为float转bool,如果a!=0.0,则为true,否则为true;如果为str转bool,若str='',str中为空,则bool(str)的内容为false,否则为true,空格也一样;只要列表中有数据那么强制类型转换为bool的时候就返回True;......