树莓派计算器
程序1:数字键盘:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause import tkinter import threading M7G= [ (1,1,1,1,1,1,0,0),#0 (0,1,1,0,0,0,0,0),#1 (1,1,0,1,1,0,1,0),#2 (1,1,1,1,0,0,1,0),#3 (0,1,1,0,0,1,1,0),#4 (1,0,1,1,0,1,1,0),#5 (1,0,1,1,1,1,1,0),#6 (1,1,1,0,0,0,0,0),#7 (1,1,1,1,1,1,1,0),#8 (1,1,1,1,0,1,1,0),#9 (0,0,0,0,0,0,0,0),#全灭 ] DM = LEDBoard(7,21,13,5,11,12,19,6,active_high=False) PX = LEDBoard(8,16,20,26,active_high=True) buff = [0,0,0,0] #def xiugai(id): # def a(e): # print(id) # # buff[0] = min(buff[0] + 1,9) # num = buff[3]+buff[2]*10+buff[1]*100+buff[0]*1000 # # #print(widget["text"]) # num = min(num*10+id,9999) # print("num=",num) # buff[0]=num//1000 # buff[1]=num//100%10 # buff[2]=num//10%10 # buff[3]=num%10 # return a def xiugai(x): num = buff[3]+buff[2]*10+buff[1]*100+buff[0]*1000 num = min(num*10+x,9999) print("num=",num) buff[0]=num//1000 buff[1]=num//100%10 buff[2]=num//10%10 buff[3]=num%10 def clr(): global buff buff = [0,0,0,0] def loop(): top = tkinter.Tk() for i in range(9): BT = tkinter.Button(top, text = i+1) BT.bind('<Button-1>',lambda x:xiugai(x.widget["text"])) BT.grid(row = (8-i)//3,column = i%3) BT = tkinter.Button(top, text = 0) BT.bind('<Button-1>',lambda x:xiugai(x.widget["text"])) BT.grid(row = 3,column = 1) BT = tkinter.Button(top, text = 'clr',command = clr) BT.grid(row = 3,column = 0) top.mainloop() d1 = threading.Thread(target = loop) d1.start() while True: DM.off() PX.off() PX[0].on() DM.value = M7G[buff[0]] sleep(1/200) DM.off() PX.off() PX[1].on() DM.value = M7G[buff[1]] sleep(1/200) DM.off() PX.off() PX[2].on() DM.value = M7G[buff[2]] sleep(1/200) DM.off() PX.off() PX[3].on() DM.value = M7G[buff[3]] sleep(1/200) |
项目2:TK数码管计算器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause import tkinter import threading M7G= [ (1,1,1,1,1,1,0,0),#0 (0,1,1,0,0,0,0,0),#1 (1,1,0,1,1,0,1,0),#2 (1,1,1,1,0,0,1,0),#3 (0,1,1,0,0,1,1,0),#4 (1,0,1,1,0,1,1,0),#5 (1,0,1,1,1,1,1,0),#6 (1,1,1,0,0,0,0,0),#7 (1,1,1,1,1,1,1,0),#8 (1,1,1,1,0,1,1,0),#9 (0,0,0,0,0,0,0,0),#全灭 ] DM = LEDBoard(7,21,13,5,11,12,19,6,active_high=False) PX = LEDBoard(8,16,20,26,active_high=True) buff = [0,0,0,0] #def xiugai(id): # def a(e): # print(id) # # buff[0] = min(buff[0] + 1,9) # num = buff[3]+buff[2]*10+buff[1]*100+buff[0]*1000 # # #print(widget["text"]) # num = min(num*10+id,9999) # print("num=",num) # buff[0]=num//1000 # buff[1]=num//100%10 # buff[2]=num//10%10 # buff[3]=num%10 # return a old_value = 0 fuhao = ' ' def xiugai(x): num = buff[3]+buff[2]*10+buff[1]*100+buff[0]*1000 num = min(num*10+x,9999) print("num=",num) buff[0]=num//1000 buff[1]=num//100%10 buff[2]=num//10%10 buff[3]=num%10 def clr(): global buff buff = [0,0,0,0] def div():#除法 pass def mul():#乘法 pass def minus():#减法 # ttt = ''.join(str(i) for i in buff) # print (int(ttt)) # ttt = str(int(ttt)) # print(eval(ttt)) pass def plus():#加法 global buff,fuhao,old_value old_value = buff[3]+buff[2]*10+buff[1]*100+buff[0]*1000 buff = [0,0,0,0] fuhao = '+' pass def equ():#= global old_value print(old_value) if fuhao == '+': num = old_value + buff[3]+buff[2]*10+buff[1]*100+buff[0]*1000 old_value = buff[3]+buff[2]*10+buff[1]*100+buff[0]*1000 print("=",num) if num > 9999: print("数据超限") old_value = 0 else: buff[0]=num//1000 buff[1]=num//100%10 buff[2]=num//10%10 buff[3]=num%10 pass def loop(): top = tkinter.Tk() for i in range(9): BT = tkinter.Button(top, text = i+1) BT.bind('<Button-1>',lambda x:xiugai(x.widget["text"])) BT.grid(row = (8-i)//3,column = i%3) BT = tkinter.Button(top, text = 0) BT.bind('<Button-1>',lambda x:xiugai(x.widget["text"])) BT.grid(row = 3,column = 1) BT = tkinter.Button(top, text = 'C',command = clr) BT.grid(row = 3,column = 0) tkinter.Button(top, text = '=',command = equ).grid(row = 3,column = 2) tkinter.Button(top, text = '/',command = div).grid(row = 0,column = 3) tkinter.Button(top, text = '*',command = mul).grid(row = 1,column = 3) tkinter.Button(top, text = '-',command = minus).grid(row = 2,column = 3) tkinter.Button(top, text = '+',command = plus).grid(row = 3,column = 3) top.mainloop() d1 = threading.Thread(target = loop) d1.start() while True: DM.off() PX.off() PX[0].on() DM.value = M7G[buff[0]] sleep(1/200) DM.off() PX.off() PX[1].on() DM.value = M7G[buff[1]] sleep(1/200) DM.off() PX.off() PX[2].on() DM.value = M7G[buff[2]] sleep(1/200) DM.off() PX.off() PX[3].on() DM.value = M7G[buff[3]] sleep(1/200) |
项目3:TK_eval数码管计算器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause import tkinter import threading M7G= [ (1,1,1,1,1,1,0,0),#0 (0,1,1,0,0,0,0,0),#1 (1,1,0,1,1,0,1,0),#2 (1,1,1,1,0,0,1,0),#3 (0,1,1,0,0,1,1,0),#4 (1,0,1,1,0,1,1,0),#5 (1,0,1,1,1,1,1,0),#6 (1,1,1,0,0,0,0,0),#7 (1,1,1,1,1,1,1,0),#8 (1,1,1,1,0,1,1,0),#9 (0,0,0,0,0,0,0,0),#全灭 ] DM = LEDBoard(7,21,13,5,11,12,19,6,active_high=False) PX = LEDBoard(8,16,20,26,active_high=True) buff = [0,0,0,0] str_temp="" def xiugai(x): num = buff[3]+buff[2]*10+buff[1]*100+buff[0]*1000 num = min(num*10+x,9999) print("num=",num) buff[0]=num//1000 buff[1]=num//100%10 buff[2]=num//10%10 buff[3]=num%10 def clr(): global buff,str_temp buff = [0,0,0,0] str_temp = "" def jisuan(fuhao):#计算 global buff,str_temp str_temp = ''.join(str(i) for i in buff) str_temp = str(int(str_temp))#去掉最前面的0 str_temp += fuhao buff = [0,0,0,0] print(str_temp) def equ():#= global buff,str_temp str_new = ''.join(str(i) for i in buff) str_new = str(int(str_new)) str_temp += str_new print(str_temp) num = int(eval(str_temp)) print(num) if num > 9999 or num < 0: print("数据超限") old_value = 0 else: buff[0]=num//1000 buff[1]=num//100%10 buff[2]=num//10%10 buff[3]=num%10 pass def loop(): top = tkinter.Tk() for i in range(9): BT = tkinter.Button(top, text = i+1) BT.bind('<Button-1>',lambda x:xiugai(x.widget["text"])) BT.grid(row = (8-i)//3,column = i%3) BT = tkinter.Button(top, text = 0) BT.bind('<Button-1>',lambda x:xiugai(x.widget["text"])) BT.grid(row = 3,column = 1) BT = tkinter.Button(top, text = 'C',command = clr) BT.grid(row = 3,column = 0) tkinter.Button(top, text = '=',command = equ).grid(row = 3,column = 2) tkinter.Button(top, text = '/',command = lambda: jisuan('/')).grid(row = 0,column = 3) tkinter.Button(top, text = '*',command = lambda: jisuan('*')).grid(row = 1,column = 3) tkinter.Button(top, text = '-',command = lambda: jisuan('-')).grid(row = 2,column = 3) tkinter.Button(top, text = '+',command = lambda: jisuan('+')).grid(row = 3,column = 3) top.mainloop() d1 = threading.Thread(target = loop) d1.start() while True: DM.off() PX.off() PX[0].on() DM.value = M7G[buff[0]] sleep(1/200) DM.off() PX.off() PX[1].on() DM.value = M7G[buff[1]] sleep(1/200) DM.off() PX.off() PX[2].on() DM.value = M7G[buff[2]] sleep(1/200) DM.off() PX.off() PX[3].on() DM.value = M7G[buff[3]] sleep(1/200) |
转载请注明:徐自远的乱七八糟小站 » 树莓派计算器