Python Forum

Full Version: HomeWork Python - Drawing window with text center.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Thank for accepted me in this Forum .
Hi everyone can u help me with this Python code .
the purpose of this exercise we have to drawing a window with text center .
So if we want to draw the text in the center of the window. so to do this, we need to position the text relatively to its center rather than its upper left corner. so exercise they give me some these parameters--- topleft, topmiddle, topright, centerleft, centermiddle, centerright, bottomleft, bottommiddle and we have to use some features for drawing window with text center like ({ "title": name title, "width": 000, "height": 000 }).

I tried to do this for 3 day now but i dont know i have to add more code or i have bring back with (width and height) now I am blocked ? hope u guy help me.
Thank u guy in advance.


def main_app(): 
    initialize(600, 300, title="first test")
    t=create_text("Hello world!", (300, 150), (255,0,0), 30, textanchor="centermiddle")
    draw_text(t)
    delay_process(5000,uninitialize)
Thank, i sorry i am new in this group i just want to find help with my python code.
Your code does not match any of the GUI toolkits I am familiar with. What are you using?
Hi actually this code is python code and this exercice is from my university and originally is france langauge so i translante from my exercice .

the main purpose of this exercice is just want to (drawing a window with text center) but i can't not go on with the code i mean i am stuck with code that why i ask in this groupe for help. hope u help me please.
You show code for a (def()) function.

Do you see any "import ..." statements in the exercise?

Paul
Hi DPaul , NO there is No , import... ,
I mean we have to change this code below to get (drawing window with text center) , so that why i dont know how to change this code and also i already tried to change but not work at all , u can see first photo i reach 50/100 but i cant not reach to 100/100 so that why i asked for help , u check link photo below :

https://postimg.cc/nMz2LTbJ

https://postimg.cc/gLnHBcqJ
-----------------------------------------------
def main_app(): 
    initialize(600, 300, title="first test")
    t=create_text("Hello world!", (300, 150), (255,0,0), 30, textanchor="centermiddle")
    draw_text(t)
    delay_process(5000,uninitialize)
It does not look like your program is build using calls to a standard library and that makes it difficult to provide assistance because I don't know what any of your code is doing. What does this do?
initialize(600, 300, title="first test")
And what do all the numbers mean in this code?
 t=create_text("Hello world!", (300, 150), (255,0,0), 30, textanchor="centermiddle")
To center text in a window you can calculate the upper left coordinates for the text using a formula like this.
x = (window_width - text_width) / 2
y = (window_height - text_height) / 2

But it looks like your text function allows setting an anchor. If you can do that then the x, y coordinates for the text are window_width/2, window_height/2.

If you can't provide more information about the supporting code that makes the window and the text I don't think you'll get much help here.
I will post this exercice maybe u guy understand better for help .
Hi if write this code u think maybe it work or not i not test yet.


def main_app(): 
    w = 600
    h = 300
    initialize(w, h, title="first test")
    t=create_text("Hello world!", (w/2, h/2), (255,0,0), 30, textanchor="centermiddle")
    draw_text(t)
    delay_process(5000,uninitialize)