Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

bsakbs

import pygame
import sys
  
  
# initializing the constructor
pygame.init()
  
# screen resolution
res = (720,720)
  
# opens up a window
screen = pygame.display.set_mode(res)
  
# white color
color = (255,255,255)
  
# light shade of the button
color_light = (170,170,170)
  
# dark shade of the button
color_dark = (100,100,100)
  
# stores the width of the
# screen into a variable
width = screen.get_width()
  
# stores the height of the
# screen into a variable
height = screen.get_height()
  
# defining a font
smallfont = pygame.font.SysFont('Corbel',35)
  
# rendering a text written in
# this font
text = smallfont.render('quit' , True , color)
  
while True:
      
    for ev in pygame.event.get():
          
        if ev.type == pygame.QUIT:
            pygame.quit()
              
        #checks if a mouse is clicked
        if ev.type == pygame.MOUSEBUTTONDOWN:
              
            #if the mouse is clicked on the
            # button the game is terminated
            if width/2 <= mouse[0] <= width/2+140 and height/2 <= mouse[1] <= height/2+40:
                pygame.quit()
                  
    # fills the screen with a color
    screen.fill((60,25,60))
      
    # stores the (x,y) coordinates into
    # the variable as a tuple
    mouse = pygame.mouse.get_pos()
      
    # if mouse is hovered on a button it
    # changes to lighter shade 
    if width/2 <= mouse[0] <= width/2+140 and height/2 <= mouse[1] <= height/2+40:
        pygame.draw.rect(screen,color_light,[width/2,height/2,140,40])
          
    else:
        pygame.draw.rect(screen,color_dark,[width/2,height/2,140,40])
      
    # superimposing the text onto our button
    screen.blit(text , (width/2+50,height/2))
      
    # updates the frames of the game
    pygame.display.update()
Comment

PREVIOUS NEXT
Code Example
Python :: What is StringIndexer , VectorIndexer, and how to use them? 
Python :: pie chart labeling 
Python :: Groupby geek link 
Python :: Iterate through string with index in python using while loop and rang 
Python :: pool.map multiple arguments 
Python :: pyglet template 
Python :: &quot;Token&quot; is not defined Pylance 
Python :: ipython run script with command line arguments 
Python :: how to make api check multiple status using drf 
Python :: circular reference detected python repl.it 
Python :: pandas split coordinate tuple 
Python :: should i learn c++ or python 
Python :: python geopandas read layer from gdb 
Python :: replicate python 
Python :: pyjone location 
Python :: napalm cli 
Python :: pylint no name in module opencv 
Python :: arma-garch python 
Python :: how to predict the output for new data with the model tested already 
Python :: python consecutive numbers difference between 
Python :: python time range monthly 
Python :: qq plot using seaborn with regression line 
Python :: python program using for for the fibonacci number 
Python :: left-align the y-tick labels | remove the current labels 
Python :: Django pull from Google Sheets 
Python :: python boto3 ypload_file to s3 
Python :: k-means clustering and disabling clusters 
Python :: struct trong Python 
Python :: compressed list 
Python :: pyqt grid layout 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =