import pygame,sys
import tkinter,time
from pygame.locals import *
import pygame
from random import randint
import pygame
from pygame.locals import *
from sys import exit
import webbrowser
from tkinter.ttk import *
from tkinter import *
import tkinter as tk
import random
import string
import math
from math import *
from time import *
import os,sys,keyword
from tkinter import messagebox,PhotoImage
from tkinter import*
from datetime import datetime
import webbrowser
from cefpython3 import cefpython as cef
import platform
from tkinter.ttk import OptionMenu
import urllib
import requests,time,random,json,struct
def p():
__author__ = 'admin'
'''
童年的回忆:掌上游戏机之赛车
'''
pygame.init()
# 设置屏幕宽度
SCREEN_SIZE = (320, 400)
# 颜色
BLACK = (0, 0, 0)
WHITE = (250, 250, 250)
BLUE = (0, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
ORANGE = (255, 128, 64)
DARK_GREEN = (0, 64, 0)
# 调试网格中单元格的长宽
cell_width = 20
cell_height = 20
# 初始化游戏状态:1/游戏开始界面 2/游戏进行中 3/游戏结束
status = 1
# 阻挡对象的列表
blocks = []
# 斑马线对象的列表
zebras = []
# 初始化得分
score = 0
speed_para = 4
clock = pygame.time.Clock()
screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32)
class Block():
def __init__(self):
# 随机生成通道位置的参照坐标
self.refer_x = randint(0, SCREEN_SIZE[0] + 1)
# 障碍物起始纵坐标
self.block_y = 0
# 随机生成通道的大小
self.passway_width = randint(4, 10) * cell_width
# 随机生成障碍物的间距,可以依据这个控制同屏出现的最大障碍物数
self.block_spacing = randint(10, 10) * cell_height
# block的高度,可以设计成随机高度
self.block_height = randint(5, 20) / 10 * cell_height
# 初始化
self.block_right_pos = (0, 0)
self.block_left_pos = (0, 0)
self.block_color = ORANGE
# 判定碰撞时需要使用block的底部纵坐标
self.block_bottom_y = self.block_y + self.block_height
# 障碍物移动情况
def block_move_down(self):
self.block_y += 1 * speed_para
# 画出本次Block()对象
def draw(self):
# 通道随机出的参照坐标为左侧边缘
if self.refer_x == 0:
self.block_right_pos = (self.passway_width, self.block_y)
pygame.draw.rect(screen, self.block_color,
pygame.Rect(self.block_right_pos,
(SCREEN_SIZE[0] - self.passway_width, self.block_height)))
# 通道随机出的参照坐标为右侧边缘
elif self.refer_x == SCREEN_SIZE[0]:
self.block_left_pos = (0, self.block_y)
pygame.draw.rect(screen, self.block_color,
pygame.Rect(self.block_left_pos, (SCREEN_SIZE[0] - self.passway_width, self.block_height)))
# 通道随机出的参照坐标距离右侧边缘间不足以满足你设定的self.passway_width通道宽度
elif self.refer_x + self.passway_width > 320:
self.block_left_pos = (0, self.block_y)
self.block_right_pos = (self.refer_x, self.block_y)
pygame.draw.rect(screen, self.block_color,
pygame.Rect(self.block_left_pos, (self.refer_x - self.passway_width, self.block_height)))
pygame.draw.rect(screen, self.block_color,
pygame.Rect(self.block_right_pos, (SCREEN_SIZE[0] - self.refer_x, self.block_height)))
else:
self.block_left_pos = (0, self.block_y)
self.block_right_pos = (self.refer_x + self.passway_width, self.block_y)
pygame.draw.rect(screen, self.block_color,
pygame.Rect(self.block_left_pos, (self.refer_x, self.block_height)))
pygame.draw.rect(screen, self.block_color,
pygame.Rect(self.block_right_pos,
(SCREEN_SIZE[0] - self.block_right_pos[0], self.block_height)))
# 更新障碍物的位置以及生成新的障碍物对象
def update(self):
global score, status
self.block_move_down()
if self.block_y == self.block_spacing:
blocks.append(Block())
if self.block_y > SCREEN_SIZE[1]:
del blocks[0]
score += 1
print(score)
# 判定碰撞时需要使用block的底部纵坐标
block_bottom_y = self.block_y + self.block_height
# 获取car的几个属性
car_pos_y = car.car_pos_y
car_pos_x = car.car_pos_x
car_width = car.car_width
# 如果block的底部在car的高度内,需要判断碰撞
if car_pos_y <= block_bottom_y <= car_pos_y + 3 * cell_height:
# 通道随机出的参照坐标为左侧边缘
if self.refer_x == 0:
# 如果car的躯壳在通道内,判定为不碰撞
if self.refer_x <= car_pos_x <= self.refer_x + self.passway_width - car_width:
pass
# car的躯壳不在通道内
else:
status = 3
# 通道随机出的参照坐标为右侧边缘
elif self.refer_x == SCREEN_SIZE[0]:
# 如果car的躯壳在通道内,判定为不碰撞
if SCREEN_SIZE[0] - self.passway_width <= car_pos_x <= SCREEN_SIZE[0] - car_width:
pass
# car的躯壳不在通道内
else:
status = 3
# 通道随机出的参照坐标距离右侧边缘间不足以满足你设定的self.passway_width通道宽度
elif self.refer_x + self.passway_width > 320:
# 如果car的躯壳在通道内,判定为不碰撞
if self.refer_x - self.passway_width <= car_pos_x <= self.refer_x - car_width:
pass
# car的躯壳不在通道内
else:
status = 3
else:
# 如果car的躯壳在通道内,判定为不碰撞
if self.refer_x <= car_pos_x <= self.refer_x + self.passway_width - car_width:
pass
# car的躯壳不在通道内
else:
status = 3
blocks.append(Block())
class Car():
def __init__(self):
# 定义car的宽度及高度
self.car_width = cell_width * 3
self.car_height = cell_height * 4
# 获取car的左上角定点坐标(这里的car区域实际上是一个矩形)
self.car_pos_x = SCREEN_SIZE[0] / 2 - (cell_width + cell_width / 2)
self.car_pos_y = SCREEN_SIZE[1] - cell_height * 4
# 设置car的移动速度
self.car_speed = 5
self.car_color = GREEN
# car的左移处理
def car_move_left(self):
self.car_pos_x -= 2 * self.car_speed
self.car_pos_x = max(0, self.car_pos_x)
# car的右移处理
def car_move_right(self):
self.car_pos_x += 2 * self.car_speed
self.car_pos_x = min(SCREEN_SIZE[0] - cell_width * 3, self.car_pos_x)
# 更新car中每个需要染色部分的坐标,以方便在car矩形图中染色出car的形状
def update_car_pos(self):
car_point_1 = (self.car_pos_x + cell_width, self.car_pos_y)
car_point_2 = (self.car_pos_x, self.car_pos_y + cell_height)
car_point_3 = (self.car_pos_x + cell_width, self.car_pos_y + cell_height)
car_point_4 = (self.car_pos_x + cell_width * 2, self.car_pos_y + cell_height)
car_point_5 = (self.car_pos_x + cell_width, self.car_pos_y + cell_height * 2)
car_point_6 = (self.car_pos_x, self.car_pos_y + cell_height * 3)
car_point_7 = (self.car_pos_x + cell_width, self.car_pos_y + cell_height * 3)
car_point_8 = (self.car_pos_x + cell_width * 2, self.car_pos_y + cell_height * 3)
car_points = [car_point_1, car_point_2, car_point_3, car_point_4, car_point_5, car_point_6, car_point_7,
car_point_8]
return car_points
# 画出car
def draw(self, car_points):
for car_point in car_points:
pygame.draw.rect(screen, self.car_color, pygame.Rect(car_point, (cell_width, cell_height)))
car = Car()
# 斑马线
class Zebra():
def __init__(self):
# 定义一个斑马线对象的高度及宽度
self.zebra_rect_height = 5 * cell_height
self.zebra_rect_width = 3 * cell_width
# 初始化斑马线区域左上角坐标
self.zebra_pos_x, self.zebra_pos_y = (0, 0)
# 获取斑马线中间的矩形块左上角坐标
self.zebra_rect_x = SCREEN_SIZE[0] / 2 - cell_width / 2
self.zebra_rect_y = self.zebra_pos_y + (cell_height + cell_height / 2)
def draw(self):
# 斑马线左侧虚线的横坐标
left_line_x = SCREEN_SIZE[0] / 2 - (cell_width + cell_width / 2)
# 斑马线右侧虚线的横坐标
right_line_x = SCREEN_SIZE[0] / 2 + (cell_width + cell_width / 2)
# 一个斑马线对象的两侧虚线高度
line_height = self.zebra_pos_y + 5 * cell_height
# 画出一个斑马现对象的两侧虚线
for i in range(self.zebra_pos_y, line_height + 1, cell_height * 2):
pygame.draw.line(screen, WHITE, (left_line_x, i), (left_line_x, i + cell_height))
pygame.draw.line(screen, WHITE, (right_line_x, i), (right_line_x, i + cell_height))
# 斑马线中间矩形块的宽度及高度
zebra_rect_width = cell_width
zebra_rect_height = cell_height * 2
# 画出斑马线对象的中间矩形块
pygame.draw.rect(screen, WHITE, pygame.Rect((self.zebra_rect_x, self.zebra_rect_y), (zebra_rect_width, zebra_rect_height)))
def update(self):
self.zebra_pos_y += 1 * speed_para
self.zebra_rect_y = self.zebra_pos_y + (cell_height + cell_height / 2)
if self.zebra_pos_y == self.zebra_rect_height:
zebras.append(Zebra())
if self.zebra_pos_y > SCREEN_SIZE[1]:
del zebras[0]
zebras.append(Zebra())
class GmaeBody():
# 退出检测函数
def checkForOut():
global status, blocks, score, car, block
for event in pygame.event.get():
# 点击×
if event.type == 12:
exit()
if event.type == 2:
# 按键为Esc
if event.key == 27:
exit()
elif event.key == 32:
if status == 1:
status = 2
elif status == 3:
score = 0
blocks = []
car = Car()
blocks.append(Block())
status = 2
# 调试用网格
def debug_grid(bool):
grid_color = WHITE
if bool:
# 调试用网格
for i in range(cell_width, 320, cell_width):
pygame.draw.line(screen, grid_color, (i, 0), (i, 400))
for j in range(cell_height, 400, cell_height):
pygame.draw.line(screen, grid_color, (0, j), (320, j))
# 游戏开始菜单的设计
def start_menu():
font = pygame.font.SysFont("arial", 30)
text_surWarn = font.render(u"START", True, BLUE)
warn_width = text_surWarn.get_width()
warn_height = text_surWarn.get_height()
pos_warn = (SCREEN_SIZE[0] / 2 - warn_width / 2, SCREEN_SIZE[1] / 2 - warn_height / 2)
screen.blit(text_surWarn, pos_warn)
# 游戏结束菜单的设计
def end_menu():
font_score = pygame.font.SysFont("arial", 30)
font_warn = pygame.font.SysFont("arial", 30, 5)
text_surScore = font_score.render("Score:%d" % score, True, RED)
text_surWarn = font_warn.render(u"RESTART", True, RED)
winner_width = text_surScore.get_width()
winner_height = text_surScore.get_height()
warn_width = text_surWarn.get_width()
warn_height = text_surWarn.get_height()
rect_width = max(winner_width, warn_width)
rect_height = winner_height + warn_height
rect_y = SCREEN_SIZE[1] / 2 - rect_height / 2
rect_x = SCREEN_SIZE[0] / 2 - rect_width / 2
pygame.draw.rect(screen, GREEN, pygame.Rect((rect_x, rect_y), (rect_width, rect_height)))
# 显示居中处理
winner_x = SCREEN_SIZE[0] / 2 - winner_width / 2
winner_y = rect_y
screen.blit(text_surScore, (winner_x, winner_y))
# 显示居中处理
pos_warn_x = SCREEN_SIZE[0] / 2 - warn_width / 2
pos_warn_y = rect_y + winner_height
screen.blit(text_surWarn, (pos_warn_x, pos_warn_y))
while True:
checkForOut()
if status == 1:
start_menu()
if status == 2:
# 初始化car
car_points = car.update_car_pos()
# 捕获按键
key_pressed = pygame.key.get_pressed()
# 如果按下LEFT键,执行挡板左移
if key_pressed[276]:
car.car_move_left()
car_points = car.update_car_pos()
# 如果按下RIGHT键,执行挡板右移
elif key_pressed[275]:
car.car_move_right()
car_points = car.update_car_pos()
# 填充颜色为黑色,刷新界面
screen.fill(BLACK)
for zebra in zebras:
zebra.update()
zebra.draw()
# 分别显示blocks列表中的每一个bloc
for block in blocks:
block.update()
block.draw()
# 画出car
car.draw(car_points)
# 开启网格调试
debug_grid(False)
if status == 3:
end_menu()
# 延迟界面刷新
clock.tick(60)
pygame.display.update()
GmaeBody()
def B():
print("上下左右键控制 一定要用力 还有开始时要随便选一个键来开启")
Snakespeed = 17
Window_Width = 800
Window_Height = 500
Cell_Size = 20
assert Window_Width % Cell_Size == 0
assert Window_Height % Cell_Size == 0
Cell_W = int(Window_Width / Cell_Size)
Cell_H = int(Window_Height / Cell_Size)
White = (255, 255, 255)
Black =(252,244,146)
Red = (62,195,247)
Green = (113,222,133)
DARKGreen = (34,132,36)
DARKGRAY = (40, 40, 40)
YELLOW = (255, 255, 0)
Red_DARK = (150, 0, 0)
BLUE = (0, 0, 255)
BLUE_DARK = (0, 0, 150)
#,fg="#228424",bg="#FEF5AA"fg="#71DE85",bg="#FCF492"
BGCOLOR = Black
UP = 'up'
DOWN = 'down'
LEFT = 'left'
RIGHT = 'right'
HEAD = 0
def main():
global SnakespeedCLOCK, DISPLAYSURF, BASICFONT
pygame.init()
SnakespeedCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((Window_Width, Window_Height))
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption('火焰工作室')
showStartScreen()
while True:
runGame()
showGameOverScreen()
def runGame():
startx = random.randint(5, Cell_W - 6)
starty = random.randint(5, Cell_H - 6)
wormCoords = [{'x': startx, 'y': starty},
{'x': startx - 1, 'y': starty},
{'x': startx - 2, 'y': starty}]
direction = RIGHT
apple = getRandomLocation()
while True:
for event in pygame.event.get():
if event.type == QUIT:
terminate()
elif event.type == KEYDOWN:
if (event.key == K_LEFT) and direction != RIGHT:
direction = LEFT
elif (event.key == K_RIGHT) and direction != LEFT:
direction = RIGHT
elif (event.key == K_UP) and direction != DOWN:
direction = UP
elif (event.key == K_DOWN) and direction != UP:
direction = DOWN
elif event.key == K_ESCAPE:
terminate()
if wormCoords[HEAD]['x'] == -1 or wormCoords[HEAD]['x'] == Cell_W or wormCoords[HEAD]['y'] == -1 or wormCoords[HEAD]['y'] == Cell_H:
return
for wormBody in wormCoords[1:]:
if wormBody['x'] == wormCoords[HEAD]['x'] and wormBody['y'] == wormCoords[HEAD]['y']:
return
if wormCoords[HEAD]['x'] == apple['x'] and wormCoords[HEAD]['y'] == apple['y']:
apple = getRandomLocation()
else:
del wormCoords[-1]
if direction == UP:
newHead = {'x': wormCoords[HEAD]['x'],
'y': wormCoords[HEAD]['y'] - 1}
elif direction == DOWN:
newHead = {'x': wormCoords[HEAD]['x'],
'y': wormCoords[HEAD]['y'] + 1}
elif direction == LEFT:
newHead = {'x': wormCoords[HEAD][
'x'] - 1, 'y': wormCoords[HEAD]['y']}
elif direction == RIGHT:
newHead = {'x': wormCoords[HEAD][
'x'] + 1, 'y': wormCoords[HEAD]['y']}
wormCoords.insert(0, newHead)
DISPLAYSURF.fill(BGCOLOR)
drawGrid()
drawWorm(wormCoords)
drawApple(apple)
drawScore(len(wormCoords) - 3)
pygame.display.update()
SnakespeedCLOCK.tick(Snakespeed)
def drawPressKeyMsg():
pressKeySurf = BASICFONT.render('Press a key to play.', True, White)
pressKeyRect = pressKeySurf.get_rect()
pressKeyRect.topleft = (Window_Width - 200, Window_Height - 30)
DISPLAYSURF.blit(pressKeySurf, pressKeyRect)
def checkForKeyPress():
if len(pygame.event.get(QUIT)) > 0:
terminate()
keyUpEvents = pygame.event.get(KEYUP)
if len(keyUpEvents) == 0:
return None
if keyUpEvents[0].key == K_ESCAPE:
terminate()
return keyUpEvents[0].key
def showStartScreen():
titleFont = pygame.font.SysFont('楷体', 100)
titleSurf1 = titleFont.render('火焰工作室', True, White, Green)
degrees1 = 0
degrees2 = 0
while True:
DISPLAYSURF.fill(BGCOLOR)
rotatedSurf1 = pygame.transform.rotate(titleSurf1, degrees1)
rotatedRect1 = rotatedSurf1.get_rect()
rotatedRect1.center = (Window_Width / 2, Window_Height / 2)
DISPLAYSURF.blit(rotatedSurf1, rotatedRect1)
drawPressKeyMsg()
if checkForKeyPress():
pygame.event.get()
return
pygame.display.update()
SnakespeedCLOCK.tick(Snakespeed)
degrees1 += 3
degrees2 += 7
def terminate():
pygame.quit()
sys.exit()
def getRandomLocation():
return {'x': random.randint(0, Cell_W - 1), 'y': random.randint(0, Cell_H - 1)}
def showGameOverScreen():
gameOverFont = pygame.font.Font('freesansbold.ttf', 100)
gameSurf = gameOverFont.render('Game', True, White)
overSurf = gameOverFont.render('Over', True, White)
gameRect = gameSurf.get_rect()
overRect = overSurf.get_rect()
gameRect.midtop = (Window_Width / 2, 10)
overRect.midtop = (Window_Width / 2, gameRect.height + 10 + 25)
DISPLAYSURF.blit(gameSurf, gameRect)
DISPLAYSURF.blit(overSurf, overRect)
drawPressKeyMsg()
pygame.display.update()
pygame.time.wait(500)
checkForKeyPress()
while True:
if checkForKeyPress():
pygame.event.get()
return
def drawScore(score):
scoreSurf = BASICFONT.render('Score: %s' % (score), True, White)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (Window_Width - 120, 10)
DISPLAYSURF.blit(scoreSurf, scoreRect)
def drawWorm(wormCoords):
for coord in wormCoords:
x = coord['x'] * Cell_Size
y = coord['y'] * Cell_Size
wormSegmentRect = pygame.Rect(x, y, Cell_Size, Cell_Size)
pygame.draw.rect(DISPLAYSURF, DARKGreen, wormSegmentRect)
wormInnerSegmentRect = pygame.Rect(
x + 4, y + 4, Cell_Size - 8, Cell_Size - 8)
pygame.draw.rect(DISPLAYSURF, Green, wormInnerSegmentRect)
def drawApple(coord):
x = coord['x'] * Cell_Size
y = coord['y'] * Cell_Size
appleRect = pygame.Rect(x, y, Cell_Size, Cell_Size)
pygame.draw.rect(DISPLAYSURF, Red, appleRect)
def drawGrid():
for x in range(0, Window_Width, Cell_Size): # draw vertical lines
pygame.draw.line(DISPLAYSURF, DARKGRAY, (x, 0), (x, Window_Height))
for y in range(0, Window_Height, Cell_Size): # draw horizontal lines
pygame.draw.line(DISPLAYSURF, DARKGRAY, (0, y), (Window_Width, y))
if __name__ == '__main__':
try:
main()
except SystemExit:
pass
def x():
wk=Toplevel()
wk.title("翻译器")
wk.geometry("300x125")
a=StringVar()
wk.configure(bg="#FCF492")
a.set("还未翻译")
z=Label(wk,textvariable=a,justify="center",fg="#228424",bg="#FEF5AA")
s=Entry(wk,fg="#228424",bg="#FEF5AA")
s.insert(END,"在此框输入翻译内容")
def get():
a.set(translate(s.get()))
def translate(content):
if content == '':
messagebox.showinfo('提示','请输入翻译内容')
else:
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
data = {}
data['i']=content
data['from']='AUTO'
data['to']='AUTO'
data['smartresult']='dict'
data['client']='fanyideskweb'
data['salt']='1538295833420'
data['sign']='07'
data['doctype']='json'
data['version']='2.1'
data['keyfrom']='fanyi.web'
data['action']='FY_BY_REALTIME'
data['typoResult']='false'
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
result = requests.post(url,data,headers=headers)
trans = result.json()
return trans['translateResult'][0][0]['tgt']
z.pack(fill=BOTH,expand=True)
s.pack(fill=X)
b=Button(wk,text="点击此按钮翻译",command=get,fg="#228424",bg="#FEF5AA")
b.pack(fill=BOTH,expand=True)
wk.mainloop()
def h():
z = strftime("%Y-%m-%d", localtime())
d = strftime("%H:%M:%S", localtime())
print("\033[33;1m╔═════════════════════════╗")
print("║", z + " " + d," ║")
print("╚═════════════════════════╝")
def y():
global search_url,search_dic,img1,cef
import tkinter as tk
import tkinter.ttk as ttk
import tkinter
search_dic={
"百度":"https://www.baidu.com/s?tn=02003390_42_hao_pg&ie=utf-8&wd={q}",
"360":"https://www.so.com/s?q={q}",
"搜狗":"https://www.sogou.com/web?query={q}",
"必应":"https://cn.bing.com/search?q={q}",
"访问网页":"url"
}
search_url="https://www.baidu.com/s?tn=02003390_42_hao_pg&ie=utf-8&wd={q}"
def problem(q):
global search_url
check_versions()
#sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
br_WindowInfo=cef.WindowInfo()
#br_WindowInfo.SetAsChild(0,windowRect=cef_pos)
#br_WindowInfo.windowRect = [100, 100, 200, 200]
if search_url=="url":
if not ("https://" in q or "https://" in q):
q="http://"+q
else:
print("True")
try:
ret = urllib.request.urlopen(url=q, timeout=3.0)
q=ret.get()
except:
pass
ret=requests.get(q)
if str(ret.status_code)[:2]=="20":
print(str(ret.status_code)[:2])
cef.CreateBrowserSync(br_WindowInfo,url=q)
else:
print(str(ret.status_code)[:2])
else:
cef.CreateBrowserSync(br_WindowInfo,url=search_url.replace("{q}",q))
cef.MessageLoop()
#cef.Shutdown()
def check_versions():
ver = cef.GetVersion()
assert cef.__version__ >= "57.0", "CEF Python v57.0+ required to run this"
def launch_the_browser(*w):
q=get.get()
root.withdraw()
problem(q)
root.wm_deiconify()
def change_seach(*w):
global search_url,search_dic
search_url=search_dic[option_var.get()]
root=tk.Tk()
root.title("星光浏览器-搜你所想")
root.configure(bg="#FCF4B2")
sw = root.winfo_screenwidth()#严子昱水印
sh = root.winfo_screenheight()#严子昱水印
ww=1000 #严子昱水印
wh=550 #严子昱水印
x = (sw-ww) / 2 #严子昱水印
y = (sh-wh) / 2 #严子昱水印
root.geometry("%dx%d+%d+%d" %(ww,wh,x,y))
#cef_pos = [x*2,y*2,ww,wh]
get=tk.Entry(root,fg="#228424",bg="#FEF5AA")
get_bu=tk.Button(root,text="搜索",command=launch_the_browser,fg="#228424",bg="#FEF5AA");get_bu.pack(side=RIGHT,fill=X)
get.pack(side=RIGHT,fill=X,expand=True)
get.bind("",launch_the_browser)
option_var=StringVar(root)
option_var.set("百度")
optionmenu=ttk.OptionMenu(root,option_var,*search_dic.keys())
optionmenu.pack(side=LEFT,fill=X)
option_var.trace("w",change_seach)
root.mainloop()
def l():
root=Toplevel() #给出一个窗口
root.title('calculator') #设置窗口名字
window=tk.Frame(root,bg="#FCF492")# 新建一个框架
window.pack(expand=tk.YES,fill='x') #tk.YES 组件显示在附配件中心位置 痛苦,fill='x'填充x方向
#定义变量
display=tk.StringVar()
#创建输入框
e=tk.Entry(window,textvariable=display)
e.grid(row=0,column=0,sticky=tk.N,columnspan=50,rowspan=2)#columnspan rowspan 从组件所置单元格算起在列表上的跨度
tk.Button(window,text='1',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'1')).grid(row=3,column=0)#INSERT 表示在光标处插入内容
tk.Button(window,text='2',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'2')).grid(row=3,column=1)#lambda:后面直接跟需要执行的东西
tk.Button(window,text='3',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'3')).grid(row=3,column=2)#lambda python内置的 简化简单函数的写法
tk.Button(window,text='4',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'4')).grid(row=4,column=0)
tk.Button(window,text='5',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'5')).grid(row=4,column=1)
tk.Button(window,text='6',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'6')).grid(row=4,column=2)
tk.Button(window,text='7',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'7')).grid(row=5,column=0)
tk.Button(window,text='8',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'8')).grid(row=5,column=1)
tk.Button(window,text='9',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'9')).grid(row=5,column=2)
tk.Button(window,text='0',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'0')).grid(row=4,column=3)
tk.Button(window,text='.',fg="#228424",bg="#FEF5AA",width=3,command=lambda:e.insert(tk.INSERT,'.')).grid(row=5,column=3)
tk.Button(window,text='+',fg="#71DE85",bg="#FCF492",width=3,command=lambda:e.insert(tk.INSERT,'+')).grid(row=2,column=0)
tk.Button(window,text='-',fg="#71DE85",bg="#FCF492",width=3,command=lambda:e.insert(tk.INSERT,'-')).grid(row=2,column=1)
tk.Button(window,text='×',fg="#71DE85",bg="#FCF492",width=3,command=lambda:e.insert(tk.INSERT,'*')).grid(row=2,column=2)
tk.Button(window,text='÷',fg="#71DE85",bg="#FCF492",width=3,command=lambda:e.insert(tk.INSERT,'/')).grid(row=2,column=3)
tk.Button(window,text='(',fg="#71DE85",bg="#FCF492",width=3,command=lambda:e.insert(tk.INSERT,'(')).grid(row=3,column=4)
tk.Button(window,text=')',fg="#71DE85",bg="#FCF492",width=3,command=lambda:e.insert(tk.INSERT,')')).grid(row=4,column=4)
tk.Button(window,text='=',fg="#71DE85",bg="#FCF492",width=3,command=lambda:cal(display)).grid(row=5,column=4)
tk.Button(window,text='删除',fg="#71DE85",bg="#FCF492",width=3,command=lambda:e.delete('0','end')).grid(row=3,column=3)
#将字符串转化为表达式,fg="#228424",bg="#FEF5AA",fg="#228424",bg="#FEF5AA"
def cal(display):
display.set(eval(display.get())) #display.get() 得到Entr内容
window.mainloop()
def b():
root = Toplevel()
root.title("练习打字,测试老师的速度!")
Label(root, text='题目:',fg="#228424",bg="#FEF5AA").grid(row=0)
Label(root, text='试卷:',fg="#228424",bg="#FEF5AA").grid(row=1)
Label(root, text='考试结果:',fg="#228424",bg="#FEF5AA").grid(row=2)
v1 = StringVar()
v2 = StringVar()
v3 = StringVar()
v1.set("点击'开始测试'按钮开始出题,想复制?不可能的(调皮)")
e1 = Entry(root, text=v1, state='disabled',fg="#228424",bg="#FEF5AA", width=40, font=('宋体', 14))
e2 = Entry(root, textvariable=v2, width=40,fg="#228424",bg="#FEF5AA", font=('宋体', 14))
e3 = Label(root, textvariable=v3, width=40,fg="#228424",bg="#FEF5AA", font=('宋体', 10), foreground='red')
e1.grid(row=0, column=1, padx=10, pady=20)
e2.grid(row=1, column=1, padx=10, pady=20)
e3.grid(row=2, column=1, padx=10, pady=20)
text = Text(root, width=80, height=7,fg="#71DE85",bg="#FCF492")
text.grid(row=4, column=0, columnspan=2, pady=5)
root.configure(bg="#FCF492")
class TypingTest:
def __init__(self):
self.time_list = []
self.letterNum = 20
self.letterStr = ''.join(random.sample(string.printable.split(' ')[0], self.letterNum))
self.examination_paper = ''
def time_calc(self):
self.time_list.append(datetime.now())
yield
def create_exam(self):
text.delete(0.0, END)
v1.set(self.letterStr)
self.time_calc().__next__()
text.insert(END, "开始:%s \n" % str(self.time_list[-1]))
user_only1.config(state='active')
def score(self):
wrong_index = []
self.time_calc().__next__()
text.insert(END, "结束:%s\n" % str(self.time_list[-1]))
use_time = (self.time_list[-1] - self.time_list[-2]).seconds
self.examination_paper = v2.get()
if len(self.examination_paper) > self.letterNum:
v3.set("输入数据有错误,作答数大于考题数")
else:
right_num = 0
for z in range(len(self.examination_paper)):
if self.examination_paper[z] == self.letterStr[z]:
right_num += 1
else:
wrong_index.append(z)
if right_num == self.letterNum:
v3.set("完全正确,正确率%.2f%%用时:%s秒" % ((right_num * 1.0) / self.letterNum * 100, use_time))
else:
v3.set("正确率%.2f%%用时:%s 秒" % ((right_num * 1.0) / self.letterNum * 100, use_time))
text.insert(END, "题目:%s\n" % self.letterStr)
tag_info = list(map(lambda x: '4.' + str(x + 3), wrong_index))
text.insert(END, "作答:%s\n" % self.examination_paper)
for i in range(len(tag_info)):
text.tag_add("tag1", tag_info[i])
text.tag_config("tag1", background='red')
user_only1.config(state='disabled')
TypingTest = TypingTest()
Button(root, text="开始测试", width=10, command=TypingTest.create_exam,fg="#228424",bg="#FEF5AA").grid(row=3, column=0, sticky=W, padx=30, pady=5)
user_only1 = Button(root, text="交卷", width=10, command=TypingTest.score, state='disable',fg="#228424",bg="#FEF5AA")
user_only1.grid(row=3, column=1, sticky=E, padx=30, pady=5)
mainloop()
def bd_baike():
def get_baike(a):
import requests,bs4
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.116 Safari/537.36'}
response =requests.get("https://baike.baidu.com/item/"+a,headers=header)
if response.status_code==200:
dic={}
try:do=response.text.split('')[0]
except:return {"summary":"对不起没有找到相关内容","list":[]}
dic["summary"]=do
response=bs4.BeautifulSoup(response.text,"lxml")
z=response.find_all(name="dl",class_="basicInfo-block basicInfo-left")
for y in z:
v=y.find_all(name="dt",class_="basicInfo-item name")
w=y.find_all(name="dd",class_="basicInfo-item value")
dic["list"]=[]
try:
for www in range(len(v)):
dic["list"].append({"key":v[www].text,"value":w[www].text})
z=response.find_all(name="dl",class_="basicInfo-block basicInfo-right")
for y in z:
v=y.find_all(name="dt",class_="basicInfo-item name")
w=y.find_all(name="dd",class_="basicInfo-item value")
for www in range(len(v)):
dic["list"].append({"key":v[www].text,"value":w[www].text})
except:pass
return dic
else:
return {"summary":"对不起没有找到相关内容","list":[]}
def got_baike(str):
k=get_baike(str)
pr_str=""
pr_str+=k["summary"]+"\n\n"
for x in k["list"]:
pr_str+=x["key"].replace("\n","")+":"+x["value"].replace("\n","")+"\n"
return pr_str
def show_baike():
text.configure(state="normal")
text.delete("1.0",tkinter.END)
text.insert(tkinter.END,got_baike(entry.get()))
text.configure(state="disable")
#print("翻译:"+fanyi(k))
import tkinter
from tkinter.scrolledtext import ScrolledText
def change(*w):
entry.configure(bg="white",fg="black")
def unchange(*w):
entry.configure(fg="#228424",bg="#FEF5AA")
baike = tkinter.Tk()
baike.title("百度百科")
baike.configure(bg="#FCF492")
entry=tkinter.Entry(baike,fg="#228424",bg="#FEF5AA")
entry.pack(fill=tkinter.X,expand=True)
entry.bind("",change)
entry.bind("",unchange)
bu=tkinter.Button(baike,text="百科一下",command=show_baike,fg="#71DE85",bg="#FCF492")
bu.pack(fill=X)
text=ScrolledText(baike,fg="#228424",bg="#FEF5AA")
text.pack(fill=tkinter.BOTH,expand=True)
baike.geometry("385x510")
baike.mainloop()
weq="此作品来之不易,请点亮小心心,不要抄袭,谢谢o(≧v≦)o"
window=tk.Tk()
root = tk.Frame()
window.title("火焰工作室--智能手机")
window.iconbitmap('huoyan.ico')
root.configure(bg="#FCF492",relief="groove")
for zzz in range(8):
window.rowconfigure(1,weight=zzz)
window.columnconfigure(1,weight=0)
window.columnconfigure(1,weight=1)
label1 = tk.Label(root,text="手机应用",fg="#71DE85",bg="#FCF492",font=("楷体", 30),height=2)
button1 = tk.Button(root,text="计算机",command=l,width=25,height=1,fg="#228424",bg="#FEF5AA",font=("楷体", 20))
button2 = tk.Button(root,text="打字速度",command=b,width=25,height=1,fg="#228424",bg="#FEF5AA",font=("楷体", 20))
button3 = tk.Button(root,text="浏览器",command=y,width=25,height=1,fg="#228424",bg="#FEF5AA",font=("楷体", 20))
button4 = tk.Button(root,text="钟表⌚️",command=h,width=25,height=1,fg="#228424",bg="#FEF5AA",font=("楷体", 20))
button5 = tk.Button(root,text="翻译器",command=x,width=25,height=1,fg="#228424",bg="#FEF5AA",font=("楷体", 20))
button6 = tk.Button(root,text="贪吃蛇",command=B,width=25,height=1,fg="#228424",bg="#FEF5AA",font=("楷体", 20))
button7 = tk.Button(root,text="百度百科",command=bd_baike,width=25,height=1,fg="#228424",bg="#FEF5AA",font=("楷体", 20))
button8 = tk.Button(root,text="赛车竞技",command=p,width=25,height=1,fg="#228424",bg="#FEF5AA",font=("楷体", 20))
label1.grid(row=0,column=0)
button1.grid(row=1,column=0)
button2.grid(row=2,column=0)
button3.grid(row=3,column=0)
button4.grid(row=4,column=0)
button5.grid(row=5,column=0)
button6.grid(row=6,column=0)
button7.grid(row=7,column=0)
button8.grid(row=8,column=0)
root.pack(fill=BOTH,expand=True,padx=3,pady=3)
messagebox.showinfo("火焰工作室",weq)
root.mainloop()
cef.Shutdown()
贪吃蛇游戏是转载作品 在此特殊说明
喜欢的朋友可以点赞评论o 你的支持是我创作的最大动力
最近考虑入手C++ 但还是会一直更新的! 部分模块还没完善 想要完整版的可以私信我 ⁄(⁄ ⁄ ⁄ω⁄ ⁄ ⁄)⁄
不懂得地方可以提问 我会尽力的解答的!!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)