Automatically resize listbox when main window is maximized (Tk) - tk-toolkit

I am using grid that has inside a listbox and 3 buttons below the listbox. When I maximize the window, they stay the same, while I need them to expand. I would not like to substitute grid with pack, as I am going to make layoung more complicated, which is simpler with grid. Is it somehow possible to expand a grid or make a grid work together with a pack? Thanks.

You need to do two things to have a gridded widget expand as the parent resizes. The widget should use the sticky option to specify which sides of the parent container it should adhere to. You also need to tell the parent how it should distribute space as it changes size using the grid_columnconfigure and grid_rowconfigure methods.
Here is an example of a gridded listbox. You should experiment with changing the sticky options to an empty string and to various other combinations of north, east, south and west to see what happens. Also try commenting out the grid_rowconfigure and grid_columnconfigure to see how that affects things.
import tkinter as tk
def main():
root = tk.Tk()
listbox = tk.Listbox(root)
listbox.grid(sticky='NEWS')
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
root.mainloop()
if __name__ == '__main__':
main()
To illustrate how this can work with some extra widgets, here is another sample with buttons on the top right. The listbox now spans 3 rows and the third row (row 2) is set to get the additional space on resizing so that the buttons do not spread out.
import tkinter as tk
import tkinter.ttk as ttk
def main():
root = tk.Tk()
listbox = tk.Listbox(root)
listbox.grid(column=0, row=0, rowspan=3, sticky='NEWS')
buttonOne = ttk.Button(root, text="One")
buttonOne.grid(column=1, row=0, sticky='NE')
buttonTwo = ttk.Button(root, text="Two")
buttonTwo.grid(column=1, row=1, sticky='NE')
root.grid_rowconfigure(2, weight=1)
root.grid_columnconfigure(0, weight=1)
root.mainloop()
if __name__ == '__main__':
main()

When having problems with widgets not growing or shrinking properly with grid, it's usually because of one or both of the following factors:
the widget hasn't been told to "stick" to the sides of the space given to it
the master hasn't been told how to allocate extra space
The first problem can be solved with using the sticky option to grid. For example:
grid .listbox -row 0 -column 0 -sticky nsew
The second problem has to do with how grid allocates extra space. By default it will leave extra space unused. It does this by allocating extra space based on a row or columns weight, which defaults to 0 (zero).
By giving a row or column a positive weight, you are asking tk to give extra space to that row and/or that column. The amount it gets is proportional to its weight. For example, if one row has a weight of one and another has a weight of two, the one with a weight of two will get twice as much of the extra space as the other row.
As a rule of thumb when using grid, always give at least one row and one column a non-zero weight so that any extra space will get used.
Here's a complete example. Run the code and resize the window to see how everything grows and shrinks. Next, comment out the final four lines and run it again to see the effect that weight has. You might also want to experiment with setting the weight on only the middle column.
package require Tk
listbox .lb
button .b1 -text "Button 1"
button .b2 -text "Button 1"
button .b3 -text "Button 1"
grid .lb -row 0 -column 0 -columnspan 3 -sticky nsew
grid .b1 -row 1 -column 0
grid .b2 -row 1 -column 1
grid .b3 -row 1 -column 2
grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1
grid columnconfigure . 1 -weight 1
grid columnconfigure . 2 -weight 1

Related

TeeChat multiple bar graph Delphi

I am trying to generate a graph where the "y" are quantity and the "x" can only be 5 items, each one has what they have to do and what they have done.
Each item is taken from different queries so I manually load the graph, then I have two problems in the x to put the titles that are different and also I assign the colors of the bars, so for example, put yellow the bars that indicate what it has what to do and blue what he has done.
In graph in the "X" the 0 for example should say house, the 1 car, 2 window, I add the data with Series1.Add (prg_caminata, ''); and Series2.Add (walk_type, ''); where the first tells me what it should have and the second what it has done.
Seems traditional usage of AddBar makes what you want:
Series3.AddBar(13, 'Car', clBlue);
Series4.AddBar(11, 'Fuel', clRed);
Series3.AddBar(8, 'Dog', clMaroon);
Series4.AddBar(12, 'Food', clGray);

how to center highcharts at the middle

I have two axis in highcharts and I dont specify the range for either. Please see graph.
For some reason, series one from 201 to 206 is taking up the whole chart while series 2 which is only -2k to 2k is being squeezed to the bottom, thereby extending the range all the way to 30k which is totally unnecessary. I think highcharts by nature wants to not have any overlap but I want that. What I'd like is for the right series to be centered, in fact I want the right axis to be centered at 0 always and can grow unrestricted in either direction. I can't hardcode any of these since I have no idea what the values could be. So Series 1 on the left is ok, but I want the value 0 for series 2 to always start at the middle of the chart. Any way to achieve that?
Try to set alignTicks as false.

Highcharts Columnrange Questions (multiple y-axes and column widths)

I'm in the process of evaluating Highcharts as a replacement for our current platform, and have some questions about how we can replicate one of our existing charts:
I've been able to recreate the basic floating stacked column chart, but need help with some of our specific features.
1) Is is possible to replicate the multiple y-axes with the columns displayed to the right of each within a single chart? If not, I suppose we could do 3 charts next to one another - and draw our own titles above (and data table below). If we go this route, is there a way to group all these elements in a single "container"? We need to export these charts to images and need to end up with a single image that looks like the one attached.
2) How would I create the inner box within each column? Do I need to draw it myself, or can I create another column series with a border and transparent fill and somehow set the width of the column to be less than the width of the main columns (note that the number of columns on each chart is dynamic, so the column widths can't be a fixed size. i.e. the inner box width needs to be a percentage of the main column width)?
3) Assuming #2 is possible, I could probably use the same technique to plot the horizontal line - just make the height 0 (or very small) and make the bar wider instead of smaller. Is there a better way?
4) How do I get the x coordinates of the columns so we can align our data table under each column?
5) Can I separate the individual points within the column. You'll notice in my jsfiddle, product 1 and product 2 are vertically aligned in the center of the column. Can I spread them out within each column as the 2 points are in the screenshot?
Thanks in advance for advice on all or any of the above.
Mike
1) You can use multiple yAxis, see the example
2) You can use renderer or mix column/column range and border parameter, example
plotOptions: {
columnrange: {
pointPadding:0.2,
color: 'rgba(255,255,255,0)',
borderColor: '#303030'
}
},
3) Use renderer, as above or scatter series with customied marker
4) Column is shape in point.element.graphic, so you can extract it.
5) as far as I know, it is not possible

Teechart - Adding / Subtracting graph values gives the unwanted rest

Working with Steema TeeChart graphs. (In particular objects: TChart, TChartSeries, TBarSeries, TLineSeries)
My task is to dynamically combine graphs when user selects some of the them, their values are added or subtracted based on XLabel value.
So this is what I get after selecting a couple of graphs and then deselecting them (which does the following:
Sets Series with DefaultBar/LineSeries
Adds values of selected graphs to the DefaultBar/LineSeries
Subtracts values of deselected graphs from the DefaultBar/LineSeries)
Result (logically) has to be 0 for all XLabels
But here is what I get:
Same graph without marks
Here are some of the values:
Can I somehow keep the actual values instead of rounded values (the ones represented on the graph), so that I will not have any rest after subtraction procedure?
I could do something like this to get rid of the rest (I know that the values will be big):
//bad solution
for Serie := 0 to Chart.SeriesCount - 1 do
for YValue := 0 to Chart.Series[Serie].YValues.Count - 1 do
if StrToFloat(FormatFloat('0.00', Chart.Series[Serie].YValue[YValue])) = 0 then
Chart.Series[Serie].YValue[YValue] := 0;
But this is not a very great solution - not scalable.
Probably related:
When I select only 1 graph and deselect it, then all the values are 0, the problem occurs when multiple graphs are selected (addition occurs)

How do I make a TCheckListBox scroll vertically?

I've got a TCheckListBox on a form. Its Columns property is set to 2, and if there are more items than can fit on-screen in two columns, it puts a horizontal scrollbar across the bottom of the control.
Thing is, the way this form it laid out, it would be much more convenient to scroll vertically. But I can't seem to figure out how to make the box do that. I thought setting Columns to 1 should work, but it doesn't.
Anyone know how to make a TCheckListBox scroll vertically instead of horizontally?
You need to set Columns to 0.
For all positive values the VCL sends a LB_SETCOLUMNWIDTH message to the underlying native list box control, with the width parameter set to the list box client width divided by the number of columns. Items that don't fit will start a new column with the same column width, so the horizontal scrollbar becomes visible.
If Columns is 0 then there is a single column that spans the entire client width of the list box, and items that don't fit will make the vertical scrollbar visible, and hide the horizontal scrollbar.
Edit:
There seems to be genuine interest what happens when a negative value is used for the Columns property.
The method TCustomListBox.CreateParams() sets the LBS_MULTICOLUMN list box style depending on the Columns property being different from 0. For negative values the style flag is set, but the VCL doesn't send the LB_SETCOLUMNWIDTH message, so the native control uses the default column width. It is documented to be:
15 times the average character width for the font used by the list box.
(Search for "The LBS_MULTICOLUMN style specifies" to find the relevant passage of text.)

Resources