首页 > 其他分享 >5.24

5.24

时间:2023-05-24 19:55:34浏览次数:38  
标签:num 30 40 button2 5.24 place 100

python电子算盘

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="orange2.jpg") # 上珠图片
backround_image2 = PhotoImage(file="yellow2.jpg") # 下珠图片
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()

 

标签:num,30,40,button2,5.24,place,100
From: https://www.cnblogs.com/wangzelin/p/17429342.html

相关文章

  • 5.24
    #include<iostream>#include<cmath>usingnamespacestd;classPoint{private:doublex;doubley;doublez;public:Point(doublea,doubleb,doublec):x(a),y(b),z(c){};frienddoubleoperator-(Point,Point);};template<class......
  • 刘铭诚:5.24今日黄金价格涨跌走势分析,原油EIA数据行情提前布局
    黄金行情走势分析——昨日黄金行情走势V型反转,白盘跌至1954一线,然后连续收阳K线反弹高点触及1980一线,上下波幅达26个点,但是整体走势还是处于4小时上下轨区间内运行,更大的空间需要等待区间破位才会选择方向。技术面上黄金价格昨日又一次试探日线布林带下轨附近也再次反......
  • 5.24打卡
    #include<bits/stdc++.h>usingnamespacestd;classPoint{public:Point(intxx=0,intyy=0){x=xx;y=yy;}Point(Point&p);intgetX(){returnx;......
  • 5.24
    #include<stdio.h>voidmain(){longinta,b,c;printf("Pleaseenteraoptionalfraction(a/b):");scanf("%ld%ld",&a,&b);printf("Itcanbedecomposedto:");while(1){if(b%a)c=b/a+1;else{c=b/a;a=1;}if(a==1){printf("......
  • 5.24打卡
     3.程序流程图 4.代码实现#include<bits/stdc++.h>usingnamespacestd;main(){intx,y,z,num=0;printf("MenWomenChildren\n");for(x=0;x<=10;x++){y=20-2*x;z=30-x-y;if(3*x+2*y+z==50)......
  • 2023.5.24-人件-5月份读后感2
    最近,我阅读了人件的下一部分,有了一些感想。过去,我对于办公环境的重视程度不够。假设除了现在的职责之外,还让你负责为手下提供办公环境和公益设施。你必须为每个人确定工作环境的种类、分配的开支总数等等,而你如何着手做这些事呢?在以后,可以更加重视办公的环境。过去,我认为加班是......
  • 最完美WIN10_Pro_22H2.19045.2486软件选装纯净版VIP38.5
    【系统简介】=============================================================1.本次更新母盘来WIN10_Pro_22H2.19045.2486。进一步优化调整。2.不支持更新,更新后精简版更新......
  • 解决fatal: unable to connect to github.com: github.com[0: 20.205.243.166]: err
    输入下面命令行pipinstall"git+git://github.com/erikwijmans/Pointnet2_PyTorch.git#egg=pointnet2_ops&subdirectory=pointnet2_ops_lib"出现错误  解决方法......
  • Electron RequestError: connect ETIMEDOUT 20.205.243.166:443
    问题描述下载electron时,卡在了下载超时,换github.comip无效、用梯子无效,直到官网这里找到了原因:MirrorYoucanuseenvironmentvariablestooverridethebaseURL,......
  • OpenJudge 1.5.24 正常血压
    24:正常血压总时间限制:1000ms内存限制:65536kB描述监护室每小时测量一次病人的血压,若收缩压在90-140之间并且舒张压在60-90之间(包含端点值)则称之为正常,现给出某......