Python Forum
HomeWork Python - Drawing window with text center.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HomeWork Python - Drawing window with text center.
#1
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)
buran write Jan-03-2021, 03:21 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.

Do not post images of code, output, etc.

Also, please check forum rules, don't hijack threads and always post in the correct subforum. This time I moved your thread
Reply
#2
Thank, i sorry i am new in this group i just want to find help with my python code.
Reply
#3
Your code does not match any of the GUI toolkits I am familiar with. What are you using?
Reply
#4
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.
Reply
#5
You show code for a (def()) function.

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

Paul
Reply
#6
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)
Reply
#7
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.
Reply
#8
I will post this exercice maybe u guy understand better for help .
Reply
#9
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HELP in python homework makashito 4 3,861 Oct-12-2021, 10:12 AM
Last Post: buran
  CyperSecurity Using Python HomeWork ward1995 1 1,930 Jul-08-2021, 03:55 PM
Last Post: buran
Exclamation urgent , Python homework alm 2 2,257 May-09-2021, 11:19 AM
Last Post: Yoriz
  Homework with python Johnsonmfw 1 1,656 Sep-20-2020, 04:03 AM
Last Post: ndc85430
  Python Homework Help *Urgent GS31 2 2,538 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Python Homework Question OrcDroid123 1 2,341 Sep-01-2019, 08:44 AM
Last Post: buran
  Python homework / functions sunhyunshine 1 2,415 May-11-2019, 05:37 PM
Last Post: MrTheOne
  Need help to finish the hat on the snowman in this Python drawing soowoosamuel 1 3,308 Apr-10-2019, 06:31 AM
Last Post: j.crater
  python homework help ASAP gk34332 1 2,942 Mar-13-2019, 07:27 PM
Last Post: ichabod801
  Python homework assigment makisha 3 3,232 Feb-28-2019, 10:21 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020