#🔒 how to make GUI/screen in python?

58 messages · Page 1 of 1 (latest)

dull sierra
#

So I want to make screen like that , I already got this code from python AI , but I still don’t know how it’s working , so can anyone explain for me how this is works?

knotty ospreyBOT
#

@dull sierra

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

jovial shale
#

Don't use AI to write code

#

I can get you started on a basic application in pygame, it just might take a minute to write

dull sierra
jovial shale
#
import pygame

pygame.init() # Get pygame set up

screen = pygame.display.set_mode((1200, 800)) # Create a display surface hooked to the window
clock = pygame.time.Clock() # Create the clock to keep the application running at a constant 60 FPS
running = True
while running:
  for event in pygame.event.get(): # Check all events
    if event.type == pygame.QUIT: # If the close button is pressed
      running = False
  
  screen.fill((255, 0, 0)) # Fill the screen surface (thus the window) with the color red (RED = 255, GREEN = 0, BLUE = 0)
  pygame.display.flip() # Update the window
  clock.tick(60) # Use the clock to tick at 60 FPS
#

Alr, lemme comment it

#

Done... hopefully that works

#

Tested it on my end and it worked

jovial shale
#

I'd also recommend actually installing Python and pygame-ce on your computer instead of using replit

dull sierra
jovial shale
#

Are you on Windows?

dull sierra
#

Sir I have one more question

What does "import" mean? And can you give me example of it

dull sierra
#

Not laptop

jovial shale
#

Do you have a laptop?

dull sierra
#

For now I want to learn python only , that's my focus

#

Because I will use it in school

jovial shale
dull sierra
jovial shale
dull sierra
#

I just started learn python before 2 days

jovial shale
#
import random # Imports python's built-in random library

print(random.randint(1, 5)) # Accessing random's random integer function and requesting a "randint" between 1 and 5
dull sierra
jovial shale
#

If you aren't familiar with import you should probably learn a lot more Python before you begin using Pygame

jovial shale
dull sierra
dull sierra
jovial shale
#

definitely lists and for-loops

#

Like this:

a = [1, 2, 3, 4, 5]
for i in a:
  print(i)
#

and how lists relate to strings

dull sierra
#

I've made my first python game yesterday want to see it?

jovial shale
#

sure

dull sierra
#

It's guess the number game

#

Ok wait

jovial shale
#

cool, my first python game too

knotty ospreyBOT
#

Hey @dull sierra!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
dull sierra
#

Wait

#

Why I can’t send more than 1k characters

jovial shale
#

A simple guess the number game can be written much smaller than 1K characters

dull sierra
#

first = True
first2 = True
first3 = False
first4 = False
winm = 0
go = 0
hs = 0
int(go)
int(hs)

while first:
win = 0
int(win)
print("Welcome to the game of Rock, Paper, scissor")
while first2:
try:
chances = input("How much life you want have?\n")
chances = int(chances)
chance = chances
first2 = False
first22 = True
except ValueError:
print("Error | pleas put a number")
while first22:
if chances == 0:
print("You cant put 0\n\n")
first22 = False
first2 = True
elif 0 > chance:
print("You cant put a negative number")
first22 = False
first2 = True
else:
first22 = False
first3 = True
while first3:
import random
n = random.randint(1,3)
n = int(n)
if n == 1:
n2 = "rock"
elif n == 2:
n2 = "paper"
else:
n2 = "scissor"
g = input("\n\nWhat do you want to chose?\n")
if g == "rock":
go = go + 1
elif g == "paper":
go = go + 1
elif g == "scissor":
go = go + 1
else:
print("unkown answer | the answer must be rock, paper or scissor")
if go == 1:
go = go - 1
if g == n2:
print("The AI took : ")
print(n2)
print("Tie")
print("\n\n\n
Your left life(s) : ")
print(chances)
print("Your wins : ")
print(win)
elif g == "rock" and n2 == "scissor":
winm = winm + 1
winm = int(winm)
elif g == "paper" and n2 == "rock":
winm = winm + 1
winm = int(winm)
elif g == "scissor" and n2 == "paper":
winm = winm + 1
winm = int(winm)
elif g == "rock" and n2 == "paper":
winm = winm + 2
winm = int(winm)
elif g == "paper" and n2 == "scissor":
winm = winm + 2
winm = int(winm)

#

else:
winm = winm + 2
winm = int(winm)
if winm == 1:
chances = chances + 1
if chances > chance:
chances = chances - 1
win = win + 1
print("The Ai took : ")
print(n2)
print("You win")
print("\n\n\nYour left life(s) : ")
print(chances)
print("Your wins : ")
print(win)
winm = 0
if winm == 2:
chances = chances - 1
print("The Ai took : ")
print(n2)
print("You lose")
print("\n\n\n
Your left life(s) : ")
print(chances)
print("Your wins : ")
print(win)
winm = 0
if win > hs:
hs = win
if chances == 0:
chances = chance
print("You lose | your highest score were : ")
print(hs)
first3 = False
first4 = True
while first4:
again = input("do you want to play again? (y/n)\n")
if again == "y":
first = True
first3 = True
first4 = False
if again == "n":
first = False
first4 = False
else:
if again != "y":
print("unknown answer | Please put y or n ")

#

That’s my game

jovial shale
#

Actually glorious

dull sierra
#

And it’s my first game ever in python

jovial shale
#

Can I show you how I would write it?

dull sierra
#

I wasn't know how to use "def"

#

That's why it's so big 😰

#

😅

jovial shale
#

It is fairly large

jovial shale
#

@dull sierra
Here it is:

from random import randint

answers = ['paper', 'rock', 'scissors']

print('Welcome to Rock, Paper, Scissors!')
while True:
    while True:
        try:
            lives = int(input('How many lives do you want? '))
            break
        except ValueError:
            print('Invalid value. You must submit an integer.')

    ai_lives = lives


    while lives > 0 and ai_lives > 0:
        while True:
            answer = input('Rock, Paper, Scissors, Shoot: ').lower()
            if answer in answers:
                rl_answer = answers.index(answer)
                ai_answer = randint(0, 2)
                break
            elif answer == 'shoot':
                print('Shoot shoot, bullet bullet gun, zap pow zap pow!')
        
        if rl_answer == ai_answer:
            print(f'\nTie!\n{answer.capitalize()} vs {answers[ai_answer].capitalize()}')
        
        elif rl_answer == (ai_answer-1) % 3:
            print(f'{answer.capitalize()} beats {answers[ai_answer].capitalize()}!\nYou scored!')
            ai_lives -= 1
        else:
            print(f'{answers[ai_answer].capitalize()} beats {answer.capitalize()}!\nAI scored!')
            lives -= 1
        
        print(f'\nCurrent lives:\n\tYOU: {lives}\n\tAI : {ai_lives}')
    
    if lives > ai_lives: print('YOU WIN!!!')
    else: print('AI WINS!!!')

    lives = ai_lives = 0
    
    again = input('Would you like to play again (y/n)? ').lower()
    if again != 'y':
        break

knotty ospreyBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.