#๐ how to i create a window in python?
92 messages ยท Page 1 of 1 (latest)
@topaz idol
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.
thanks
No problem
That is the best part
want to make a window? need to get something
The hard work has been done for you
because it got hundred of thousands of them, can't package them all in there
Other languages, such as C++ have few libraries and you need to code everything by yourself
it's the ecosystem that makes python so popular and powerful
interesting
Sure if you want to make a window, you can do it, but you will do it in hundreds of lines
With packages, in a few lines you are done
For example with turtle
well, there is lots of them as well online, but it's more work to import and use them
from turtle import Screen
screen = Screen()
screen.exitonclick()
Would make you exit the screen when it's you click on the window, with an if statement probably you can do what you want
Yeah probably
Turtle is built in
No need to install it
thats great then
so i could make it work with pynput to close the screen when i press Q?
In Java, you need to import java.util.Map before you can use it, while in Python things like that are built into the syntax.
unless you use the PyCharm GUI for it you can also go to the console and make sure your venv is active and do
py -m pip import
thats rlly cool
yeah the pycharm console is useful
And u can resize the screen to ur liking with screen.setup(x,y)
hmmmmm, so why doesnt this work?
from pynput import keyboard
from turtle import Screen
while Screen():
def on_press(key):
if key == keyboard.Key.A:
exit(Screen())```
you don't want Screen() as the while condition and not inside the exit()either
but i thought if it was the while condition
it would work while the screen is on no?
I kinda suck at python, but you might be able to do
from turtle import screen
screen = Screen()
def closeScreen():
screen.exit()
screen.listen()
screen.onkeypress(closeScreen, โAโ)
It is hard to assume what a function does from a package you have never worked with before. You should check out the documentation from the turtle module online
Screen() is a class, not a function so it won't do anything but it will give you the options to do so
ok so im testing out some attributes, and im running into a problem where i run the script, and the screen appears for like 1/10 of a second then dissapears
whats the difference
is a class just an object type????
A class is a collection of functions and attributes mainly
๐
I just woke up after not sleeping 28 hours
go to sleep
I cannot, I gotta sleep at night too because I have school tomorrow
You should see Rust. Rust's standard library doesn't even include random number generation. Almost everything is a separate package.
holy
yeah, "bring your own batteries" ๐
Go on the other hand got all kinds of batteries included
tkinter is part of the python standard library
hmmm, so whats the tkinter import called?
e.g
from tkinter import (???)```
consult the docs:
https://docs.python.org/3/library/tkinter.html
ok so you seem knowledge
knowledgable*
WHAT IS A FUN ARGUEMENT
WHAT IN TARNATION
IS A FUN ARGUEMENT
from turtle import *
from turtle import Screen
from pynput import *
from pynput import keyboard
screen = Screen()
screen
screen.bgcolor("black")
if screen.onclick():
screen.setup(900, 200)```
what gave you the idea to use if screen.onclick(): ?
if click when screen
if there is a clcik
...
that's not how it works, it kind of seems like you are throwing random things at the wall and hoping they work
i mean
can you blame me
how much programming have you done?
i made uhhhhh
a few scratch games
dipped my toes
I think if you are new, i would recommend to do some kind of structured learning, like cs50x or cs50p classes, those are great for beginners
what are those
free classes by harvard,
cs50x is intro to programming: some scratch (just first thing, then some C, python, html, css, javascript) it sort of introduces you to things conceptually across a few languages - very good for building foundations and mental map of how to think in general programming
cs50p is intro to python: its purely python and more about learning the language syntax than conceptual things, a bit easier overall, but both are good intros
i know more than a few programming concepts
so i guess i'll take the python one
thanks
Probably a function.
You're supposed to pass a function as an argument to screen.onclick(), as in screen.onclick(function_that_handles_clicks)
That'd be my guess
This help channel has been closed. 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.