按下开始按钮后,它运行程序,但它不允许我使用右下角的退出按钮,我不知道为什么它会这样做。有人能帮忙吗。我希望它继续运行该程序,但仍然允许我使用该按钮,因此,如果我想中途退出,它将允许我。项目描述:“对于我的项目,我将使用python创建一个随机迷宫生成软件。我将创建一个网格呈现给用户。该软件将从左上角开始,然后创建迷宫,沿随机方向运行,最后在右下角结束。”
#importing the pygame Module
import pygame
import sys
from random import randint
from time import sleep
#assigning the dimensions of window
width = 450
height = 450
#setting colours to be used (used rgb values)
black = (0,0,0)#for background of maze
white = (255,255,255)#for colour of grid
red = (255,0,0)#colour for actual maze
blue = (0,0,255)#colour for backtrack
green = (0,255,0)#will be used to show solution
lightgrey = (170,170,170)#used as colours for buttons
darkgrey = (100,100,100)
def moveup(x,y):
pygame.draw.rect(SCREEN,red,(x+1,y-w+1,19,39),0)
pygame.display.update() #moves a square up and makes red
def movedown(x,y):
pygame.draw.rect(SCREEN,red,(x+1,y+1,19,39),0)
pygame.display.update() #moves a square down and makes red
def moveleft(x,y):
pygame.draw.rect(SCREEN,red,(x-w+1,y+1,39,19),0)
pygame.display.update() #moves a square left and makes red
def moveright(x,y):
pygame.draw.rect(SCREEN,red,(x+1,y+1,39,19),0)
pygame.display.update() #moves a square right and makes red
def backtrack(x,y):
pygame.draw.rect(SCREEN,red,(x+1,y+1,18,18),0)
pygame.display.update()#this will change colour of cell back to red to indicate it
#going back through cells to find unvisited one
def singlecell(x,y):
pygame.draw.rect(SCREEN,blue,(x+1,y+1,18,18),0)
pygame.display.update()#this will change colour of cell to indicate it going back
#through cells to find unvisited one
def solutionchange(x,y):
pygame.draw.rect(SCREEN,green,(x+8,y+8,5,5),0)
pygame.display.update()#This will add a smaller square to the big square to make a
#route
def drawgrid(x,y,w):
for i in range(1,21): #this creates cells from left to right then goes down to next
#row.
x = 20
y = y+20
for a in range(1,21):
pygame.draw.line(SCREEN,white,[x,y],[x+w,y])#top line of cell
pygame.draw.line(SCREEN,white,[x,y+w],[x,y])#left line of cell
pygame.draw.line(SCREEN,white,[x+w,y+w],[x,y+w])#bottom line of cell
pygame.draw.line(SCREEN,white,[x+w,y],[x+w,y+w])#right line of cell
cell_list.append((x,y))
x = x + 20
def mazemaker(x,y):
visited.append((x,y))#adds co-ords to list of cells visited
cellstack.append((x,y))
while len(cellstack) > 0:
sleep(0.05) #adds delay between movements so you can see it being made.
pickmovecell = []
if (x+w,y) not in visited and (x+w,y) in cell_list: #multiple if used and not
#elif as if they all true they all need to take place or if some true they all
#need take place
pickmovecell.append("right")
if (x-w,y) not in visited and (x-w,y) in cell_list:
pickmovecell.append("left")
if (x,y-w) not in visited and (x,y-w) in cell_list:#checks if x and y co-ords of
#next cell is visited or not
pickmovecell.append("up")#adds to list that it can move up
if (x,y+w) not in visited and (x,y+w) in cell_list:
pickmovecell.append("down")
if len(pickmovecell) > 0: #this point onwards will pick randomly which direction
#to go from available diretions.
choice = randint(0,len(pickmovecell)-1)
directionmove = pickmovecell[choice]
if directionmove == "up":
solution[x,y-w] = x,y
moveup(x,y)
y = y-w
visited.append((x,y)) #This part checks what direction has been picked and
#changes x and y co-ords based on it and adds new cell to lists.
cellstack.append((x,y))
elif directionmove == "down":
solution[x,y+w] = x,y
movedown(x,y)
y = y+w
visited.append((x,y))
cellstack.append((x,y))
elif directionmove == "left":
solution[x-w,y] = x,y
moveleft(x,y)
x = x-w
visited.append((x,y))
cellstack.append((x,y))
elif directionmove == "right":
solution[x+w,y] = x,y
moveright(x,y)
x = x+w
visited.append((x,y))
cellstack.append((x,y))
else:
x,y = cellstack.pop()#pop removes last thing added to list this allows me to
#make the maze go back
singlecell(x,y)#calls function to show moving back
sleep(0.04)
backtrack(x,y)#calls function to make cells red again
def solutionroute(x,y): #This will make it solve the maze and call the colour change
#function to add a little dot to indicate solution route
solutionchange(x,y)
while (x,y) != (20,20):
x,y = solution[x,y]
solutionchange(x,y)
sleep(0.1)
def menu():
global SCREEN,x,y,w,cell_list,visited,cellstack,solution
#maze variables
x = 0 #x axis
y = 0#y axis
w = 20#width of cell
cell_list = []#contains all x and y values of all cells
visited = []#This will keep track of all visited cells and order visited in
cellstack = []#order and cells checked/gone through
solution = {} #This is a dictionary which means it wont have duplicate coordinates
#which a list would allow
pygame.init() #initalising pygame
SCREEN = pygame.display.set_mode((width,height))#creates the actual window
SCREEN.fill(black)#fills the background as black
smallfont = pygame.font.SysFont('Corbel',35)#sets type of font and size of it
starttext = smallfont.render('Start' , True , white)#sets what text i want on button
#to variable
quittext = smallfont.render("Quit",True,white)
while True:
for ev in pygame.event.get():#if x in top right clicked window shuts down
if ev.type == pygame.QUIT:
pygame.quit()
sys.exit()
if ev.type == pygame.MOUSEBUTTONDOWN:#Checks if mouse button is clicked
if 170 <= mouse[0] <= 170+140 and 170 <= mouse[1] <= 170+40:#if button is
#clicked it runs start functiom
start()
if ev.type == pygame.MOUSEBUTTONDOWN:
if 170 <= mouse[0] <= 170+140 and 220 <= mouse[1] <= 220+40:#if button is
#clicked quits program
pygame.quit()
sys.exit()
mouse = pygame.mouse.get_pos()#Stores the x,y cords of mouse to a variable
if 170 <= mouse[0] <= 170+140 and 170 <= mouse[1] <= 170+40:#if mouse hovers over
#button it changes colour
pygame.draw.rect(SCREEN,lightgrey,[170,170,140,40])
else:
pygame.draw.rect(SCREEN,darkgrey,[170,170,140,40])
if 170 <= mouse[0] <= 170+140 and 220 <= mouse[1] <= 220+40:
pygame.draw.rect(SCREEN,lightgrey,[170,220,140,40])
else:
pygame.draw.rect(SCREEN,darkgrey,[170,220,140,40])
SCREEN.blit(starttext , (170+35,170+7))#Adds text to the button
SCREEN.blit(quittext , (170+35,220+7))
pygame.display.update()#Adds the additons to the window
def start():#This function calls all the other functions to make the program work
SCREEN = pygame.display.set_mode((width,height))#Resets the window so button not
#there
SCREEN.fill(black)#fills the background as black
smallfont = pygame.font.SysFont('Corbel',25)#sets type of font and size of it
quittext = smallfont.render("Quit",True,white)
while True:
for ev in pygame.event.get():
if ev.type == pygame.MOUSEBUTTONDOWN:
if 300 <= mouse[0] <= 300+140 and 425 <= mouse[1] <= 425+20:#if button is
#clicked goes back to menu
pygame.quit()
sys.exit()
mouse = pygame.mouse.get_pos()#Stores the x,y cords of mouse to a variable
if 300 <= mouse[0] <= 300+140 and 425 <= mouse[1] <= 425+20:
pygame.draw.rect(SCREEN,lightgrey,[300,425,140,20])
else:
pygame.draw.rect(SCREEN,darkgrey,[300,425,140,20])
SCREEN.blit(quittext , (300+50,425))
pygame.display.update()
x,y = 20,20 #sets start x and y co-ords
drawgrid(40,0,20) #calls draw grid function
mazemaker(x,y)#makes maze
solutionroute(400,400)#calls function to show solution route to user
sleep(30)#Waits 30 seconds
menu()#Runs main menu again
menu()
将start()函数更改为以下代码。一旦迷宫完成构建,它将显示“退出”。)
def start():#This function calls all the other functions to make the program work
SCREEN = pygame.display.set_mode((width,height))#Resets the window so button not
#there
SCREEN.fill(black)#fills the background as black
smallfont = pygame.font.SysFont('Corbel',25)#sets type of font and size of it
quittext = smallfont.render("Quit",True,white)
drawgrid(40,0,20) #calls draw grid function
x,y = 20,20 #sets start x and y co-ords
mazemaker(x,y)#makes maze
solutionroute(400,400)#calls function to show solution route to user
while True:
mouse = pygame.mouse.get_pos()
for ev in pygame.event.get():
if ev.type == pygame.MOUSEBUTTONDOWN:
if 300 <= mouse[0] <= 300+140 and 425 <= mouse[1] <= 425+20:#if button is
pygame.display.get_surface().fill((0, 0, 0))
#clicked goes back to menu
return
#Stores the x,y cords of mouse to a variable
if 300 <= mouse[0] <= 300+140 and 425 <= mouse[1] <= 425+20:
pygame.draw.rect(SCREEN,lightgrey,[300,425,140,20])
else:
pygame.draw.rect(SCREEN,darkgrey,[300,425,140,20])
SCREEN.blit(quittext , (300+50,425))
pygame.display.update()
以下是logcat中显示的错误。
我已经连接了我的Windows10和linux机器。我想远程关闭我的Windows10电脑从我的Linux。然而,当我使用下面的Java程序时,它并没有关掉我的窗户。我试过用 相反,在程序中输出命令,但我得到了相同的结果。 输出
我试图将24个添加到我的的,但当我运行它时,我发现没有添加任何按钮。(至少,它们不可见!)。我试着给一个背景色,它是可见的。有人知道我做错了什么吗? 这是我的代码(还有一个类): 其他(主要)类别:
问题内容: 我有这个jQuery来响应被单击的按钮并调用REST方法: 不仅仅是不调用REST方法-此处理程序显然根本没有触发,因为我没有看到任何警报(“ 单击该按钮。 ”或“ 嘿,嘘! ”)。 该脚本 是 被添加- I可以通过它步骤,和瓦尔(如“unitval”) 被 被分配相应的值。 那么,为什么要单击这样声明的按钮: …没做什么? 这是要添加的脚本(从“视图”>“页面源”): 这可能并不相关
因此,我使用javafx创建了这个应用程序,它有一个登录屏幕,但我在这方面没有任何成功,我已经在这个项目的这个小部分工作了一些天,它根本不能以任何方式工作。我尝试这样做,我看了一些教程,其中大部分都是像下面的代码一样,但它对我来说不起作用,如果有人能帮我解释为什么我的标签文本没有改变(这就是我如何测试登录是否成功),这将是很好的,下面是代码: 控制器: FXML格式