下面就是代码:
首先做了一个问答式个性化,后边做了一个忘八数介绍,最后就是计算机了,有什么意见欢迎提出。白嫖不用申明哦。
#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个半小时的东西终于好了