- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
import pygame
pygame.init()
display_width = 1024
display_height = 600
display = pygame.display.set_mode((display_width,display_height))
blue = (0,0,200)
light_blue = (0,0,255)
black = (0,0,0)
red = (200,0,0,255)
light_red = (255,0,0)
white = (255,255,255)
light_purple = (139,0,139,255)
purple = (128,0,128,255)
smallfont = pygame.font.SysFont("comicsansms", 50)
medfont = pygame.font.SysFont("Algerian", 50)
largefont = pygame.font.SysFont("Algerian", 85)
altSmall = pygame.font.SysFont("Algerian",20)
altMed = pygame.font.SysFont("Algerian",30)
altLarge = pygame.font.SysFont("Algerian",75)
extrasmall = pygame.font.SysFont("comicsansms",15)
clock = pygame.time.Clock()
def text_objects(text, color,size = "small"):
textSurface = smallfont.render(text, True, black)
if size == "small":
textSurface = smallfont.render(text, True, color)
if size == "medium":
textSurface = medfont.render(text, True, color)
if size == "large":
textSurface = largefont.render(text, True, color)
if size == "altMed":
textSurface = altMed.render(text,True,color)
if size == "altSmall":
textSurface = altSmall.render(text,True,color)
if size == "medFont":
textSurface = medfont.render(text,True,color)
if size == "smallFont":
textSurface = smallfont.render(text,True,color)
if size == "extraSmall":
textSurface = extrasmall.render(text,True,color)
return textSurface, textSurface.get_rect()
def alt_med_pos_message_to_screen(msg,color,x,y,size = "smallfont"):
screen_text = smallfont.render(msg,True,color)
display.blit(screen_text,[x,y])
class Button():
text = str()
x = int()
y = int()
width = int()
height = int()
inactive_color = None
active_color = None
action = str()
active = bool()
def __init__(self,text,x,y,width,height,inactive_color,active_color,action,text_color,text_size,active):
self.text = text
self.x = x
self.y = y
self.width = width
self.height = height
self.inactive_color = inactive_color
self.active_color = active_color
self.action = action
self.text_color = text_color
self.text_size = text_size
self.active = active
def nothing():
pass
def handle_event(self,event):
if self.is_hovered() and event.type == pygame.MOUSEBUTTONDOWN:
self.action()
def text_to_button(self,surface):
textSurf, textRect = text_objects(self.text,self.text_color,self.text_size)
textRect.center = ((self.x+(self.width/2)), self.y+(self.height/2))
surface.blit(textSurf, textRect)
def is_hovered(self):
cur = pygame.mouse.get_pos()
return self.x + self.width > cur[0] > self.x and self.y + self.height > cur[1] > self.y
def drawButton(self, surface):
if self.active:
pygame.draw.rect(surface,self.inactive_color,[self.x,self.y,self.width,self.height])
if self.is_hovered() and self.active:
pygame.draw.rect(surface, self.active_color,[self.x,self.y,self.width,self.height])
self.text_to_button(surface)
def home_screen():
backgroundImg = 'C:/Users/student/Desktop/Geometry Calc/Images/programbackground.png'
statisticsImg = 'C:/Users/student/Desktop/Geometry Calc/Images/statistics.png'
algebraImg = 'C:/Users/student/Desktop/Geometry Calc/Images/algebra-math.png'
geometryImg = 'C:/Users/student/Desktop/Geometry Calc/Images/geometry.png'
background = pygame.image.load(backgroundImg)
statistics = pygame.image.load(statisticsImg)
algebra = pygame.image.load(algebraImg)
geometry = pygame.image.load(geometryImg)
homeScreen = True
StatisticsButton = Button("Statistics",100,250,250,85,purple,light_purple,statistics_formulas,black,"smallfont",True)
GeometryButton = Button("Geometry",100,315,250,85,purple,light_purple,geometry_formulas,black,"smallfont",True)
AlgebraButton = Button("Algebra",100,390,250,75,purple,light_purple,algebra_formulas,black,"smallfont",True)
while homeScreen:
for evt in pygame.event.get():
StatisticsButton.handle_event(evt)
GeometryButton.handle_event(evt)
AlgebraButton.handle_event(evt)
if evt.type == pygame.QUIT:
homeScreen = False
pygame.quit()
quit()
display.blit(background,[0,0])
alt_med_pos_message_to_screen("Formula Hack",red,display_width/2-150,100,size = "smallfont")
StatisticsButton.drawButton(display)
GeometryButton.drawButton(display)
AlgebraButton.drawButton(display)
display.blit(statistics,[350,250])
display.blit(geometry,[350,325])
display.blit(algebra,[350,400])
pygame.display.update()
def statistics_formulas():
inStatistics = True
backgroundImg ='C:/Users/student/Desktop/Geometry Calc/Images/StatisticsBackground.png'
Zscore = Button("1. Z-score",900,25,75,35,purple,light_purple,zscore,black,"extraSmall",True)
statsBackground = pygame.image.load(backgroundImg)
while inStatistics:
for evt in pygame.event.get():
Zscore.handle_event(evt)
if evt.type == pygame.QUIT:
inStatistics = False
pygame.quit()
quit()
display.blit(statsBackground,[0,0])
Zscore.drawButton(display)
pygame.display.update()
def geometry_formulas():
print("geometry")
def algebra_formulas():
print("algebra")
def zscore():
screen = pygame.display.set_mode((display_width, display_height))
font = pygame.font.Font(None, 32)
clock = pygame.time.Clock()
input_box = pygame.Rect(100, 100, 140, 32)
color_inactive = pygame.Color('lightskyblue3')
color_active = pygame.Color('dodgerblue2')
color = color_inactive
active = False
text = "0"
done = False
input1 = int(text)
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.MOUSEBUTTONDOWN:
# If the user clicked on the input_box rect.
if input_box.collidepoint(event.pos):
# Toggle the active variable.
active = not active
else:
active = False
# Change the current color of the input box.
color = color_active if active else color_inactive
if event.type == pygame.KEYDOWN:
if active:
if event.key == pygame.K_RETURN:
text = ""
elif event.key == pygame.K_BACKSPACE:
text = text[:-1]
else:
text += event.unicode
screen.fill((30, 30, 30))
# Render the current text.
txt_surface = font.render(text, True, color)
# Resize the box if the text is too long.
width = max(200, txt_surface.get_width()+10)
input_box.w = width
# Blit the text.
screen.blit(txt_surface, (input_box.x+5, input_box.y+5))
# Blit the input_box rect.
pygame.draw.rect(screen, color, input_box, 2)
pygame.display.flip()
clock.tick(30)
home_screen()
如果知道有帮助的话,我只需要存储整数、值,谢谢!问题所在的代码的主要部分位于函数“zScore”下的底部附近,但它确实使用了在整个代码中创建的一些类。如有任何帮助,我们将不胜感激。
我首先尝试做的是将变量文本存储在另一个变量中,并使用此输入变量执行基本操作,但当然输入框只接受字符串。然后我尝试使用 int() 函数尝试将输入框中输入的字符串转换为整数,但这也不起作用。我也无法在同一屏幕上使用多个输入框。
最佳答案
您只需在用户按 Enter 键时将 text
变量转换为 int 即可。这应该有效:
if event.key == pygame.K_RETURN:
try:
input1 = int(text)
except ValueError:
print('Invalid input')
text = ""
关于python - 如何在 pygame 的一个表面上有多个输入框并将这些输入存储在变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53089636/
我有以 xyz 点格式表示 3D 表面(即地震断层平面)的数据。我想创建这些表面的 3D 表示。我使用 rgl 和 akima 取得了一些成功,但是它无法真正处理可能会自行折叠或在同一 x,y 点具有
我正在尝试将此 X、Y、Z 数据集拟合到未知表面。 不幸的是,线性拟合不足以显示表面数据。我认为多项式拟合可能适合这种情况。另外,问题是我不知道如何建立多项式拟合函数来完成曲面拟合。 任何帮助都会很棒
我已经用plotly构建了一个表面图表,并且我正在尝试根据我自己的文本获得hoverinfo。奇怪的是它不再工作了。 library(plotly) x % layout(dragmode = "tu
我有以下数据: library(rgl) x y,y->z,z->x) zmat <- matrix(data = z, nrow = 6, ncol = 5, byrow = FALSE) surf
我正在使用 DXVA 视频解码器。它工作正常,但我想与另一个 IDirect3D9 设备对象共享解压缩的表面。 我读了this文件,我调用 IDirectXVideoDecoderService::C
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
import pygame, sys, os.path pygame.init() # set up the colours # R G B BLACK = ( 0,
我的目标是在 pygame 实例内显示一个颜色图,以 49 个元素 ndarray 的形式反射(reflect)实时输入,范围从 -6 到 2,标准化为 0 到 1 的值。到目前为止,我正在使用 ma
我在 Visual C# -> surface -> v2.0 -> MS visual C# 2010 express 中的 Surface Application (WPF) 模板中工作。 我正在
我正在尝试在 JavaFX 中实现我自己的 3D 表面动画,但我不理解它应该工作的一切,有人可以帮助我理解哪个应该放在哪里吗? 已经知道使用类构建Mesh需要类对象TraingleMesh然后必须使用
根据我的阅读,我不相信 SurfaceView 可以设置动画,但我会问这个问题: 我在 ViewFlipper 中有一个 surfaceView 对象。当 ViewFlipper 向左或向右移动到新的
我想在 android 屏幕上有一个图像,图像的不同部分可以点击。我的意思是,如果它是 3 个圆圈的图像,我希望能够单击这些圆圈中的每一个, 然后我可以为每个可点击的圆圈添加不同的功能。对于下图中的示
我有一个通过kinect获得的点集,现在我想创建一个网格。我正在尝试使用 CGAL 库并且正在关注 this example . 我使用的是 VS2010,它运行没有任何错误,但是当然它没有在行中
在让我的 SurfaceView 显示我的相机预览时遇到一点问题。我在这里查看了一些问题并通过 Google 搜索了一些 tuts,但我认为这可能是我这边的一个小错误,我只是没有看到。 代码 publ
任何人都可以为我指出一些类(class)或对以下情况提出任何建议吗? 我有一个 SurfaceView,它有一个背景图像,我希望在其上绘制其他位图。我想支持以下操作: 点击一下,新的位图就会添加到背景
我正在尝试学习表面 View 并且我确实读到了它。 所以,我试着制作了一个游戏,我认为它可以帮助我更好地学习。 我创建了一个表面 View 类,如下所示: class SnakeEngine exte
我希望笑脸 div(在用户进入墙壁后显示)将覆盖主迷宫表面而不改变笑脸大小:你能帮帮我吗? 这是 fiddle 链接: http://jsfiddle.net/uqcLn/66/ 这是笑脸 div:
我有一组 (x,y,z) 点,这些点具有相应的法线和值。所以数据的形式是 [x y z nx ny nz c]。我想在这些垂直于这些法线的点上绘制一个 3D 表面,并且具有与该值对应的颜色。所以我想要
我有一个不是函数图的表面的 3D 数据集。数据只是 3D 中的一堆点,我唯一能想到的就是在 Matlab 中尝试 scatter3。 Surf 将不起作用,因为表面不是函数图。 使用 scatter3
假设我有一个函数,例如: 现在,我想绘制它的曲面图(matplotlib plot_surface )。我使用 np.arange(stop,end,increment) 构造了三个数组。 在这里,我
我是一名优秀的程序员,十分优秀!