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.
Related
I'm writing a little program to create an excel file. I've managed to change style attributes of cells, but I was wondering if there was a function or an attribute that automatically changes cells' width based on the length of the cells' values. Just like when you double click on the column to do it manually.
I found a way to change the width to a specific number, but every column's title has a different length and I would end up having a lot of blank space.
Maybe a function calle autofit or something similar?
I want to find the height of the table dynamically, so that whenever the table's height reaches a specific number, I can create another slide and split the table. Because number of text in cell varies, the height will be different for each time the code is run.
Is it possible to do it in pptx-python?
No. "Stretched" table cell heights and the resulting overall table height turns out to be a rendering concern and those values are not recorded in the .pptx file.
A row or cell can have a minimum height that is set in the file, but once the cell gets more text than it can display it will automatically grow beyond that minimum and the PowerPoint renderer is the one to do that. It does not record the value it ends up with.
One way to approximate the rendered dimensions of a table cell is to render the the text yourself in some sort of graphical environment and see how big it gets. That value will depend on the font type-face and point-size, so you'll need to know those. Any way you go about it will be approximate; there are a lot of small complicating factors and even one renderer like OpenOffice might not always render exactly like another, say PowerPoint or Google Docs. For example, there may also be column width adjustment rules that PowerPoint uses to help accommodate a heavily populated cell, not just making the cell taller.
I've heard of at least one developer having reasonable results using wxPython as a rendering environment in which to approximate PowerPoint's rendering behavior, but I believe that was for a single textbox. Doing the same for a table is potentially much more complex.
Another route might be to use VBA to drive an actually running instance of PowerPoint. That may give access to the rendered size of the table.
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
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.
When using wx.grid for creating table with wxpython, how can I automatically extend the number of rows and columns in the table once the user resizes the frame?
If I create 5*5 table(grid) to fit on my frame and user resizes the frame( say, makes it bigger), how can I implement automatic increase to the number of rows and/or column which responds to increase in frame size?
Sadly there is no builtin way to do this that I'm aware of. You'll need to catch the frame's EVT_SIZE and then use AppendRows and AppendCols as necessary with the grid. You'll need to take into account how much the frame size has changed and only append when it gets bigger, not smaller.