0

I draw texts with wxPython on my DC. The position of the text is depending on the width of my frame, in this case the variable "w".

It is calculated in my code like this:

    dc.DrawText("Overview", w/2-wt/2, 10)

But now, if the forumlar "w/2-wt/2" is smaller than a certain value I want to set it to a fix value.

I know how to do it with an if than else, but my personal favorit would be to do it inline, to keep my code short an simple.

Is there a way to do this?

K-Doe
  • 509
  • 8
  • 29
mk1337
  • 105
  • 10
  • 1
    You can use [`if-else`](https://stackoverflow.com/a/11880682/10041823) inline as well ? – Alexandre B. Aug 02 '19 at 10:10
  • Alexandre's comment provides the answer and keeps the code short but does it achieve your aim of `simple`? For maintenance purposes you may be better keeping your code explicit and easy to follow. `dc.DrawText("Overview",w/2-wt/2 if w/2-wt/2 >= 100 else 22, 10)` for example doesn't look simple. – Rolf of Saxony Aug 02 '19 at 15:08

0 Answers0