#🔒 how to make GUI/screen in python?
58 messages · Page 1 of 1 (latest)
@dull sierra
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.
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
I know , that’s why I want to learn , if you can help me learning more about python that will help me so much , and I appreciate that sir
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
Yes, if you have any Pygame or Python questions, many people on this server would love to help
I'd also recommend actually installing Python and pygame-ce on your computer instead of using replit
Unfortunately I don't know how to download the original python
Are you on Windows?
Sir I have one more question
What does "import" mean? And can you give me example of it
Do you have a laptop?
Yes , but I usually work on ipad , I will download original one in my laptop in the future
For now I want to learn python only , that's my focus
Because I will use it in school
It means what it literally says.
import will include the entire pygame library as part of your current script.
After importing, you will have access to pygame's many functions and classes with their methods
(Classes are not like a "classroom" class, but more of a Python object constructor. There're more intermediate though if you're just starting with Python)
Alright , can you give me example of how it works in coding?
It will be hard to learn Python on a laptop, but ig it's possible
sure
I just started learn python before 2 days
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
How much import is there in Python?
If you aren't familiar with import you should probably learn a lot more Python before you begin using Pygame
Wdym? Like what are the libraries Python comes with?
All I know is :
Print
Input
While
If / elif / else
Def
Int/str/float
Yes
What should I learn now
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
I've made my first python game yesterday want to see it?
sure
cool, my first python game too
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.
A simple guess the number game can be written much smaller than 1K characters
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\nYour 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\nYour 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
Actually glorious
And it’s my first game ever in python
Can I show you how I would write it?
Sure
I wasn't know how to use "def"
That's why it's so big 😰
😅
It is fairly large
@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
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.