As an example, I have an entry, and several optionmenus located below a treeview widget. I am using the grid manager, and the treeview has a columnspan equal to all the widgets along it's lower side.
Since specifying the width of an entry or an optionmenu is in characters (the width in px of those characters is in turn based on the font size/family chosen for the widgets), and specifying the width of a column in a treeview is in pixels, how can I calculate the lengths of both a column and the widget underneath it so that they are visually linked by their positions (the length being the same)?
I found a great example of treeview. It might help to provide some insight. Here is the link
Create a table using treeview with control of column widths
Related
How to set dynamically rowheight in Treeview widget of tkinter?
I mean if I am adding wrapped text into the row then how can I set that particular row's height without affecting other rows' heights. Image 1 is the Treeview object created without selecting the row. When I select the row it cuts out the text I have inserted(Image 2).
Same thing happens if I insert a second row(Image 3), it cuts down to the rowheight I have mentioned in style.
In a recent change what I have done in my program is to check for the length of the string passing to the Treeview. While filling Treeview with the rows set the 3 types of flags for 3 type of heights. Small, Medium and Large are set according to rows passing to the Treeview. Now, I have three flags to check for when I'm done with filling rows of Treeview. Checking from Small to Large, the highest flag set for my case is deciding factor for my all row heights for Treeview so I send according "rowheight" to Treeview.And that's all... I get all rows clear to be read, whenever I apply new changes.
For now this solution is serving for my project. But, still expecting to get individually settable rowheights for rows of Treeview.
Using Tkinter I want to create a scrollable list(rows and columns) with images and editable text. The first column should contain images and the second column should contain tags(text) for the respective images in the previous column.
Hence a row should contain an image in a column and text in the next column.
Please let me know, what widget i need to use in Tkinter in order to achieve this.
Thanks for any help.
I would use a single frame for the images and editable text. You can use a text widget for the editable text, and align them using grid.
Then, place the frame in a canvas so that it can be scrolled. There are many questions and answers on this site related to scrolling a frame. See, for example, this answer: https://stackoverflow.com/a/16198198/7432
I am trying to achieve the following effect using a Tkinter python app:
The user can define a finite number of list elements, aka categories.
I then would like to present these categories next to each other, based on the following approach:
l=Label(self.body,text='Category: ')
l.pack(side=Left)
for i in range(0,len(self.categories)):
l=Label(self.body,text=self.category[i])
l.pack(side=LEFT)
self.body.pack(fill=BOTH)
Of course, this does not work. Is there an elegant way to "wrap" a whole label at the widget borders?
Thanks!
You have to know the size of the frame you are using to pack the labels into, and the width of the label. You can set the width parameter for the label, but it uses a size that depends on the font used i.e. the same "width=" results in different label widths for different font sizes. So it can not be done with the code you posted. Link to label parameters http://effbot.org/tkinterbook/label.htm
I am trying to build a grid of frames in each there is a matplotlib figure.
When I resize the window the figure remain with fix size and are not resizing to fit the empty space.
Is there a way to make the figure change its size according to the canvas (hopefully that it does change with the window size)?
This is how I do the embedding in each frame:
self._figure = pyplot.figure(figsize=(4,4))
self._axes = self._figure.add_subplot(111)
self._canvas = FigureCanvasTkAgg(self._figure, master=self._root)
self._canvas.get_tk_widget().grid(row=1,column=1,rowspan = 4)
This is most likely related to this question. The gist is that there are two parts to making a Tk grid cell grow:
Use the sticky keyword when applying grid to your widget, e.g., widget.grid(..., sticky=Tkinter.NSEW (Python 2.7) to make widget be able to grow in all four directions. See this documentation for more details.
Tell the parent/master to make the respective column/row grow when resizing by calling parent.grid_columnconfigure(...) and/or parent.grid_rowconfigure(...) with the desired row, column, and weight keyword. E.g., parent.grid_columnconfigure(col=0, weight=1) makes the first column take all available space (as long as there are no other columns, or they have not been similary configured). See the grid_columnconfigure documentation and the grid_rowconfigure documentation for more details, e.g., about how the weights affect multiple columns/rows.
This page contains many more details about grid layouts.
I'm trying to figure out how i can have a 3 column layout where the (smaller) left and right columns are resizable with a draggable separator on each side of the center/main area. I've tried using splitwindow but that seems to only split in two parts.
Hope someone can give me pointers on how it can be done.
I susggest that you create three panels, side by side. When one of the panels is resized by the user, you will have to adjust the size of the other panels to compensate - so that there are no gaps or overlaps. You can do this by handling the resize event, probably in the parent windows of the three panels.
Another way, which requires you to write less code, would be to use wxGrid with one row and three columns and zero width labels for columns and rows. You will lose the flexibility of panels, but wxGrid will look after the resizing of the column widths for you.