I want to use an input parameter in my Python code, but instead of being asked in the Python editor toolbox, the user should be prompted in the Python Turtle Graphics window. I believe that this should be done by built-in write(), but I have no idea how to implement it.
"Write" is used for the turtle to write something in the window. You can not currently have an input in the turtle window, unless you code it all yourself.
Related
I need to clear the IDLE shell, using code. The only way I know of to remove the text is closing the shell and reopening. I want this to be able to put into code that requires refreshing the shell, for example a memory game, giving a string of words, and then removing them, or some kind of animation made of text pictures.
Essentially I want to do something like shell.clear() or something similarly easy to use. It can be a function or whatever, but I'd like it to be easy to put into some preexisting code.
I do not know if such a thing is possible, but if you have any pointers, tips or code, I'd appreciate the help.
IDLE 3.7.3 on Mac.
You can use:
from os import system
#for windows
system('cls')
#for Unix based systems
system('clear')
Or if you are inside IDLE or Python interpreter you can use this function:
def cls(): print ("\n" * 100)
That you can call cls() whenever you need to clear your screen.
I am currently using getch, getkey and the getstr functions from the curses module and have found them not user-friendly. Why?
They are all slower to detect a keypress than the python input() function.
You have to hold the key down for longer than the usual press-down to make the program recognise it.
In my scenario though, I have a curses window, so I don't know how to, or if it's possible to use non-curses functions on it. I would like to know if there is a way of using the input() function on the curses window or just be able to position the input for the user to enter text.
If it's not possible, can you please provide an alternative. Thanks!
Note: The user has to be able to see what they are typing as well.
view = curses.newwin(1,1,15,10)
#Get user request even with curses window
data = input()
Is there any difference between window.listen(), screen.listen(), and turtle.listen()?
I see them used differently in various programs but assume they can be called interchangeably.
I suggest you read Difference between turtle and Turtle?. The short answer is that the turtle library provides two API's, a function-based one and an object-oriented one. (Behind the scene, the function one is built atop the object one at load time.) The confusion begins when you mix the two. My answer in the link explains one way to avoid doing so.
turtle and screen have separate inputs.
For example:
turtle.onclick() and screen.onclick() may seem the same but screen.onclick() is referring to the general window while turtle.onclick() is referring to the turtle module itself.
Turtle
When calling turtle.onclick() you are activating the (onclick) function, to call your argument function whenever the user clicks specifically on the turtle object.
Screen
When calling screen.onclick() you are activating the (onclick) function, to call your argument function whenever the user clicks anywhere on the window.
This is equivalent to turtle.onscreenclick() because onscreenclick() refers to the entire screen. Hence the name screenclick rather than just click which refers to the turtle object.
Listen
So because turtle and screen have separate input functions, you'll need separate listening functions.
So
turtle.listen() listens for overall the entire turtle module's inputs, whilst screen.listen() listens for screen / window inputs.
Trying to get started with Python, autocomplete would be very useful.
As I now understand, Python is dynamically typed and defining the return type of functions is not required. Not so great for autocomplete, obviously.
Therefore I tried to type-hint my local variable in order to enable the IDE to autocomplete. While the IDE checks the existence of the type I hint, this seems to have no effect on auto complete at all.
Is there a way to get autocomplete or should I forget about it when using Python?
This is my code:
import turtle
def draw_square():
screen = turtle.Screen() # type: turtle.Screen
screen.bgcolor("blue")
screen.exitonclick()
draw_square()
There is autocomplete feature present in pycharm. I'm using pycharm professional. I have attached a screenshot.
I made a program in python which allows you to type commands (e.g: if you type clock, it shows you the date and time). But, I want it to be fullscreen. The problem is that my software doesnt have gui and I dont want it to so that probably means that I wont be using tkinter or pygame. Can some of you write a whole 'hello world' program in fullscreen for me? What I am aiming for is for my program to look a bit like ms-dos. Any help??? By the way, im very new to python (approximately 4 weeks).
NOTE: I have python 3.4.1
Since Vista, cmd.exe can no longer go to full-screen mode. You'll need to implement a full-screen console emulator yourself or look for another existing solution. E.g. ConEmu appears to be able to do it.
Solution
Use your Operating System services to configure parameters.
<_aMouseRightClick_>->[Properties]->[Layout]
Kindly notice, that some of the python interpreter process window parameters are given in [char]-s, while some other in [px]:
size.Width [char]-s
size.Height[char]-s
loc.X [px]
loc.Y [px]
So adjust these values so as to please your intentions.
You may set negative values for [loc.X, loc.Y] to move/hide window edges "outside" the screen left/top edges