How to make Tkinter.Label justify correctly - python-2.7

I am having an issue getting the text inside a label to left justify in Tkinter. I have tried using the justify=Tkconstants.LEFT but that doesn't seem to work. I have also tried anchor=Tkcontants.W but that doesn't seem to help either. The text always appears in the center of the label. Here is what I have regarding the label:
LookupOutput = Tkinter.Label(UI,textvariable=User,justify=Tkconstants.LEFT)
LookupOutput.grid(row=5, column=0, columnspan=5, padx=5)
I assume it has something to do with my columnspan but I don't know how to fix it. Does anyone have an idea on how to get this thing to left justify the text?

The proper way to have the text in a label aligned to the left of the widget is with the anchor attribute. A value of "w" (or by using the Tkinter constant W) stands for "west".
LookupOutput = Tkinter.Label(UI,textvariable=User,anchor=Tkconstants.W)
The justify attribute only affects text that wraps.
If that isn't working, the problem might not be with the text in the label. It might be that your label doesn't occupy the space you think it does. An easy way to check this is to give the label a distinctive background color so that you can distinguish the label from its parent.
I notice that you aren't using the sticky attribute when you call grid -- that may also cause problems. By default grid will align a widget in the center of the space allocated to it. If you want it to "stick" to the left side of the space that was given to it, use sticky="w" (or, again, use the Tkinter constant).

Related

Scrolling but wrapped pad in NCurses

I'm trying to make a text reader/pseudo-command-line a la man, but I'm having difficulty making the text scroll the way I'd like it to. At first I was having trouble getting new text to appear while scrolling, but eventually I found that pads would fix that for me, and I'm currently integrating them.
My question is, how can I get text to wrap within the pad? My program currently automatically refreshes when it is resized, so defining the pad to have as many columns as the terminal wouldn't fix everything. Can I get the pad to automatically resize itself as needed when my terminal receives a KEY_RESIZE? Not just the displayed size, but the size of the pad as well, such that text is pushed down a row due to the end of the pad. Additionally, will resizing it still keep the text, moving it down rows if necessary, or will I need to refresh the content of the pad?
Unfortunately, I'm having trouble finding resources with these details, and the documentation in ncurses doesn't elaborate on the behavior of resizing a pad.
Thanks a lot!
Edit after answered: ncurses doesn't do this, so I'm going to try instead making some arrays of strings, one to store the text from the file (broken at \n), and another for the line wrapping (refreshed on KEY_RESIZE, with each string having a max length of the terminal rows), parts of which are printed to the body window based on scrolling position and such. I'm making this edit so anyone else seeing this problem in the future can see what my solution is. I haven't done this yet, so I'll edit this again if it fails. Thanks again to Stack Overflow for helping with this!
ncurses will not do what you intend in this case:
A pad is like a window, true, and addch will wrap -- but the viewport which you are using to display data in the pad is not a window, and wrapping at the right side of the pad is not necessarily related to that viewport.
Once the text has wrapped, ncurses will not remember what that was, and re-wrap text if you resize the window (or pad).
A pad is mainly useful when you want to display just part of a window, e.g., if the screen is not large enough for the text you want to display.
If you want to resize and re-wrap, your program should allow for rewriting all of the text in the window (to lay it out as you intend) and not rely on ncurses to decide how to re-wrap text.

How to check if the length or width of Row in a window is greater than the width of its parent window C++

I wanted to wrap the existing text of checkbox into multiline if the width of row exceeds the width of its parent window. I am not really sure how to do that.
The image I want to show the checkbox string
The image where the string is cropped and only shows if window is resized or maximized
You are going to have a problem with this I am afraid.
The setting for making a checkbox multiline is ES_MULTILINE and if you look here you will see that it states:
To create an edit control using the CreateWindow or CreateWindowEx function, specify the EDIT class, appropriate window style constants, and a combination of the following edit control styles. After the control has been created, these styles cannot be modified, except as noted.
So, it would seem to me that you have three ways forward, depending on what you feel is the best or most elegant for you.
Set your control in the resource editor as multiline anyway. Then it doesn't matter and will wrap. No need to have to change the setting.
Implement the needed functionality to limit the size the window can be reduced to. I can show you how if you are interested. This way, if you set the control resize properties correctly it can resize larger but only reduce down the a known dimension (ie: the dimensions you created it in the resource editor).
Possibly have two controls in the same place, one as multiline and one as single. And when you decide which you want to show, swap the visibility. But I think this is a bad idea, bit of a headache, and not worth the hassle.
IMHO I would do both ideas 1 and 2 and I would happily extend my answer to provide more information.
Update
Having looked at your images and the comments about translations then there is a fourth idea. If you use a third party application to manage the translations and use satellite DLL files then you can adjust the resources on a language by language basis. I sometimes have to make the default width for some windows wider due to their verbose nature.
I have set BS_MULTILINE for the checkbox. The minimum size of the window is fixed but I just want the checkbox to fit in that. I expect it to show at least one word in the same line as other labels and remaining words in second line. So I am checking if the total width of the first row is greater than the width of window then show the string with \r\n in it else show normal string. However, I want to align first line or the first word of the checkbox with the checkbox and remaining words should come below the first word. Currently, the checkbox is in between two lines which looks weird. Is there anyway I can do this?

Text is stretching to a new page rather weirdly

Not sure if I am missing something but I am wrapping blocks of text around a bounding box. However, when it stretches to a new page, the text continues in the lower middle of the page instead of the top bit.
Not quite sure why and not sure if this is the default behavior of bouncing box since I am specifying x,y coordinates; although I couldn't find such thing in the docs
The code below reflects more or less what I have
pdf.bounding_box([absolute_bounds_left, pdf.cursor], width: absolute_bounds_right) do
pdf.text('Something')
pdf.text('Something else')
if something
pdf.text('Another thing')
...
end
...
end
I realised that if you specify a height option, the overflowing text will flow to the next page at [x,y]. So I realised that the if you do not supply a height, the only thing different is that it will stretch until the end of the page and then behave exactly the same, start at position [x, y].
I searched a bit more into the docs to validate this and indeed there is an example. Sorry no permalink so you have to search for it: http://prawnpdf.org/manual.pdf -> [text/free_flowing_text.rb]
If you notice there is another method, span which solved my free flowing text issue. It also comes with a position which amongst the standard :left, :right and :center it takes a numeric value as an offset on the y axis. See here

How do I draw a line on a Lazarus form?

I often use a TPanel or TGroupBox to group my form controls.
Now I need to draw just a straight line like the border of a Panel or GroupBox.
How do I do this on LAZARUS?
Thanks in advance!
Note: The technique must work on both Linux and Windows
As an optical line separator you should use either the TBevel component with Shape property set to one of the following values bsTopLine, bsBottomLine, bsLeftLine or bsRightLine depending on which line you currently need and resize it to a smaller size (in your case you can use bsTopLine or bsBottomLine and resize the bevel vertically):
Or you can use a special component called TDividerBevel which except the single line adds to this optical divider also a caption:
Here's what I've finally done but I'm not sure if this is the RIGHT way so I won't accept my answer. If there's someone else who can point out any issues with this, please let me know. I found this pretty straightforward as well :)
Place a TGroupBox on the form.
Leave the Caption property blank. Now it should look like a panel with only borders.
Use the mouse and drag the bottom border towards the top. Now it looks like a line.
Well, I personally think this method is NOT efficient as it would take up more memory space than just a real straight line. Anyway, so far it seems to work for me :)
Here's the screenshot - look towards the bottom (just above the last text box). The only issues is that on the sides of the line, it shows the lines bending. I think I should set the properties correctly than dragging with the mouse.

Wrap text around the image

Can a list of Label objects and picture be aligned such a way that if the label has space in the right side it should make use of the full length before wrapping to the next line.
This is because of that fact that I may not have pictures of full height of the pane always.
For shorter images I want to make use of the space at the bottom.Note that the text is a nodelist of label nodes.