In Tkinter, I would like to have different fonts in one Label.
So, the practical case is this: I have a Text Widget and in the text widget there is a bunch of Labels, each containing three lines: Title, Duration - Channel, and Description.
I would like to make the Title stand out by making it bold. Can this be done? So far I didn't find information that helped me out, and in the past I encountered the issue and didn't manage to find a solution.
I would prefer not to have 3 labels, because I have nice borders around the label. It would really complicate things.
Of course, I don't mind a bit of complication if it is necesary, but if it is unnecesary, then that would be nice. It seems like it should be normal functionality, like some tags or so.
You can't use more than one font in a label. If you need multiple fonts you'll have to use a Canvas or a Text widget, or combine multiple labels inside a frame. Arguably, the simplest solution will be a three line text widget.
Related
I want to add a text box to a folium map that gives more information about the source data and how the map can be used as a resource. If possible, I want it to look and behave almost identically with the LayerControl function (and a bonus would be if it were collapsible too).
(This is incidentally my attempted work-around for what I initially had wanted: the ability to hover over an icon next to each item in the LayerControl panel to display a popup infobox, but I suspect that this would be far more demanding, since it involves modifying folium.LayerControl).
So far, I have only been able to find solutions that add a marker to the map, but this isn't really doing the same thing as a simple text box. Other solutions involve adding text at a specific location on the map, but I need the textbox to be displayed wherever the user navigates. This is the closest solution I've come across to what I need, but this only adds text above the map, and I'm not sure that modifying the html code wouldn't be reducible to the same solution as adding text at a specific location.
As my code is quite long and with a lot of nested layouts I won't put it in here but I essentially have a QHBoxLayout which I want to have a different background colour as the others. I First thought about changing the stylesheet but I quickly learned that the layout is not affected by that as it apparently is not a visual element. Hence my Question: How do I create simple (geometric) elements? Is it even possible to just have a colored box in the background and some lables and pictures in the foreground?
I tried just using a big QTextEdit block and colouring this with the StyleSheet but this didn't get me the results I hoped for as It'd be hard to align the text the way I want it to be and add pictures.
I am writing a kicad plugin, and I need to create a GUI for this plugin. Because kicad uses wxpython, that is what I am using.
I have already figured out that placing my ui items using the layout sizers just isn't gonna give me the control I need to create the window I want. I know I can set the position of elements, and have been using that to create the ui I need.
The problem however, is that my window gets bigger than what would be reasonable (in some situations). Therefore I want to make it scrollable.
I have been playing around with wxformbuilder, and I found the wxScrolledWindow. That got me this far:
This is roughly what I want, except, when you want to place stuff within the scrolledWindow, you have to place one of the "sizers" in it (as far as I can tell at least), in which you place your buttons. The problem with that is, that, to my knowledge, setting the position of buttons in any of the sizers just has no effect at all.
So, my question is: how do I achieve this effect? and, is this even possible?
edit:
As an example of what I am trying to put within the scrolledwindow, this is a rough version of the ui I want to create (and want to be scrollable). (I want to eventually have, probably an icon button above each of the checkbox columns to indicate what they are for).
The final result would need to look something like this (the white squares being small images / buttons, also, in reality being not on the window bar,but in its own not scrolling section):
An example of something I wasn't able to achieve using sizers is, getting those checkboxes so close together, without making them appear off center. Different widgets seem to have different sizes, and checkboxes without border are especially small, so they end up appearing off center, example:
Also, those images above each column of checkboxes, which don't scroll, need to line up with the X coordinates of those scrolling checkboxes, which also seems very non trivial. Though also really hard to get right if I could give everything exact coords, so I might need to give up on that specific idea of making those not scrollable.
I'm building a generic, data-driven Tkinter form. Each row has a label on the left and an input field on the right. With simple test data, it works to use a Label for the label text -- but when the desired label text is longer than the Label field, it simply truncates.
Once the form has been built, I won't need to vary the label text dynamically: the text will be known at construction time. But I don't know the universe of possible label strings. I want the form to accommodate longer label text by word-wrapping the label to multiple lines, expanding vertically. This should of course expand the row in which the label is embedded.
Per Create resizable/multiline Tkinter/ttk Labels with word wrap, I presume I should use a Text widget for word wrapping and disable it as an input field. But I don't know how to constrain it horizontally (to engage the word wrapping) while expanding it to exact size vertically.
In other words, the processing sequence should go something like this:
Determine the overall width of the parent.
Allocate the width of the Text field relative to the parent. (I imagine I would use grid_columnconfigure(weight=), but am happy to entertain suggestions.)
Word-wrap the Text contents to fit its width.
Vertically expand the Text block to display all lines.
Propagate the vertical size outward to the parent.
This may have a straightforward answer that would become apparent once I better understand the workings of Tkinter geometry managers in general and Grid in particular. I've read http://effbot.org/tkinterbook/grid.htm and http://effbot.org/tkinterbook/pack.htm without yet having a big "Aha!" moment. I'd be grateful for reference material that addresses this kind of issue as well.
Thanks for any help!
You are looking for the Message widget:
The Message widget is a variant of the Label, designed to display multiline messages. The message widget can wrap text, and adjust its width to maintain a given aspect ratio.
If you want fancy things like multiple fonts, you'll need to move to a Text widget. If you just want a longer version of a Label, though, Message is a good choice.
I have seen some ways of making colored text in textview in Python pygtk. the issue seems that it will just print text in that colour or make the whole line that color rather than for certain items make them a certain colour.
I want it to where I type "" that is will colour is blue. or if there is "string" in the text view it will be orange or any kind of
and if there is an '#comment' then it will be italicized and grey.
not sure if it helps, but I have a part where as I am typing it writes the text to a page. is it possible to to keep this kind of syntax coloring active?
I hope this makes sense.
any help is much appreciated! Thank you!
Use GtkSourceView for syntax highlighting. Don't reinvent the wheel.
In general, what you are looking for, I'd say, is to use regular expressions (re module, there are abundant of questions on this here...probably some for the exact patterns you need) to find the patterns you mention above in your TextBuffer. That means you need to connect a signal to the buffer so you see what the user types. Then you'll need a set of TextTags (one tag per formatting rule/pattern) to apply to regions of the buffer where the regular expressions match the patterns you've described. Finally you want to apply the tags to the buffer and those TextTags can reformat the text-display in the TextView in an array of ways (as the documentation says here).
Without any supplied code, it's hard to be precise on where you might be having a problem.
Hope it points you in the right direction...
Mind though that if you overwrite the GTK-theme, that another user could have a theme with e.g. orange background in the TextViews, so you should be careful with making sure that it will work visually independent of what theme you have.