用python做一个计算机

下面就是代码:

首先做了一个问答式个性化,后边做了一个忘八数介绍,最后就是计算机了,有什么意见欢迎提出。白嫖不用申明哦。

#gg
def a(e):
    a=input('print a color')
    while a != 'red' and a != 'blue' and a != 'green' and a != 'orange' and a != 'yellow' and a!='purple' :
        print('please try again') 
a=input('print a color')
if a != 'red' and a != 'blue' and a != 'green' and a != 'orange' and a != 'yellow' and a!='purple' :
    print('please try again')
    a(1)

#做个小提示
import pygame  
import sys  
pygame.init()  
screen = pygame.display.set_mode((800, 600))  
pygame.display.set_caption('忘八数')  
text = 'Try 012345679 times a multiple of 9'  
font = pygame.font.Font(None, 36)  
running = True  
while running:  
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:  
            running = False  
    screen.fill((0, 0, 0)) 
    text_obj = font.render(text, True, (255, 255, 255))  
    screen.blit(text_obj, (200, 200))  
    pygame.display.update()  
pygame.quit();
#搞一个则个都要累死人
#正式做计算器啦
import tkinter as tk
class Calc(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.title("计算器")
        self.memory = 0  
        self.create()
    def create(self):
        btn_list = ['清除', 'M->', '->M',' ',
                    '7', '8', '9', '/',
                    "4", "5", "6", '*',
                    '1', '2', '3', '-',
                    '0', '.', '=', '+']
        r = 1
        c = 0
        for b in btn_list:
            self.button = tk.Button(self, text=b, width=5,
                                    command=(lambda x=b: self.click(x)))
            self.button.grid(row=r, column=c, padx=3, pady=6)
            c += 1
            if c > 3:
                c = 0
                r += 1
        self.entry = tk.Entry(self, width=24, borderwidth=2,
                              bg=a, font=('Consolas', 12))
        self.entry.grid(row=0, column=0, columnspan=4, padx=8, pady=6)
#还差一点点了
    def click(self, key):
        if key == "=": 
            result = eval(self.entry.get())
            self.entry.insert(tk.END, " = " + str(result))
        elif key == "清除":  
            self.entry.delete(0, tk.END)
        elif key == "->M": 
            self.memory = self.entry.get()
            if "=" in self.memory:
                ix = self.memory.find("=")
                self.memory = self.memory[ix + 2:]
            self.title("M=" + self.memory)
        elif key == "M->":  
            if self.memory:
                self.entry.insert(tk.END, self.memory)
 
        else: 
            if "=" in self.entry.get():
                self.entry.delete(0, tk.END)
            self.entry.insert(tk.END, key)

#最后2句话了!!!!!
if __name__ == "__main__":
    Calc().mainloop()
#花了3个半小时的东西终于好了    

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值