How do I use a grid to center a frame in a window? - tcl

I have created a frame containing a label and a button. When I expand the toplevel window, the frame is anchored at the top left of the window. How do I center the frame within the toplevel window? I am using the "grid" geometry manager.
frame .frame
ttk::label .frame.title -text "Rocket 1"
ttk::button .frame.button -text "Launch!"
grid .frame
grid .frame.title
grid .frame.button
How do I vertically and horizontally center the label and button?

You should set the anchoring of the grid within its space. In your case:
grid anchor . center
Note that because you have two grids nested within each other (one in the toplevel, one in the frame) you have to think carefully about which one has the extra space. It's often instructive to set the fill color of frames to something garish (bold red, green, blue, etc) while fixing layout bugs.
To show what I mean, I've added:
# With apologies to people with Daltonism; pick other colours if you prefer
. configure -bg green
.frame configure -bg red
to your script, giving a window like this:
Now, if I do:
grid anchor .frame center
it looks identical (the grid of widgets is now centered within the red area that is shrunk-to-fit around them), but if I do:
then you can see that the group of widgets on the red background (.frame) is now placed centrally within the green area (.).

Related

Why does my image keep zooming in within my grid or flex boxes?

I am a beginner web developer student. I am trying to create two columns and three rows of flex boxes within a grid container. I have text on one side with an image of a delicious looking pancake in the second flex box which is at the top right corner.
Even though I had the image set to 100% to fill in the box, my image keeps zooming in so that it only shows a partial image. Using different images, I spent quite a lot of time realigning the container and boxes and looked up multiple ways to resize and reposition the image but for some reason, it keeps zooming in. How do I get the image to zoom out evenly so that the user can see the full pancake image while it also fills in the entire flex box?
Original Image: https://www.koreanbapsang.com/wp-content/uploads/2015/04/DSC9846-350x350.jpg
enter code hereCode Pen: https://codepen.io/rylew09025/pen/ZEWaNOj

Make one div overlap another?

I've got a line of text that gets revealed when a dropdown arrow is clicked. However, certain pages of the site I'm building have divs that extend beyond the single line of text I'm hiding.
Here's an example:
The green div (ordinarily white) needs to overlap the div above (blue body with orange margins). My goal is to cover up a link that will sit 15px beneath the arrow under the word "Bukau", leaving the text to left unaffected.
I have a hunch the solution I'm looking for might involve making the 'green' div fixed/changing z-index values.
I also want to make sure the green block acts like an extension of the content below it, getting pulled up/down when a user clicks the arrow toggle.
Appreciate any advice/suggestions!
Solution: Simple as making the top-margin on the 'green' div -50 or so pixels, and setting its position to 'relative'

Allow a panedwindow to scroll vertically and stretch horizontally

I am trying to write a simple GUI for editing key-value pairs in TCL+Tk. It is based on a vertical ttk::panedwindow widget containing an arbitrary number of horizontal ttk::panedwindow widgets, each with a ttk::entry on the left side and a text widget on the right side. Below the main ttk::panedwindow is a frame containing buttons to do things like saving and loading files and adding new rows. This works fine, with all widgets scaling as I expect them to, but when more rows are added they get squeezed together or stretch the window.
Trying to make the window vertically scrollable didn't work properly. Tk is unfortunately very picky about what it will let me attatch scrollbars to, so I couldn't just put one on the main ttk::panedwindow. I tried various hacks listed on wiki.tcl.tk, but most of them use a canvas widget and scroll in both directions. If I remove the horizontal scrollbar, it won't be there anymore but the widgets will still extend beyond the edge of the window or stop before the edge of the window.
I also tried BWidget, but I didn't understand the relationship between the ScrolledWindow and ScrollableFrame widgets that I was told to use together. When I followed the examples they had the same problem as the canvas version. I suspect that they actually use a canvas internally rather than implementing a true scrollable frame.
How can I make the main interface scale to the dimensions of the window while also allowing vertical scrolling? I'm using Linux, if that helps.
I made a GIF to show what I want:
dissapearing scrollbar is optional, it just happened like that. The changing scribbles represent the lines of text adjusting to the available space.
So… you want the content to be “natural” in the vertical direction, yet stretched in the horizontal direction? Tricksy.
Your basic approach is going to be to put a frame (or ttk::frame) inside a canvas, put your “interesting” content inside the frame and add a scrollbar to the canvas. However, that's not the tricky bit. The tricky part is that you need to notice changes to the dimensions of the canvas and to the dimensions of the frame; a change to the frame should cause the adjustment of the canvas's bounding box, and a change to the canvas should cause adjustment to the requested width of the frame.
To notice a change to the size of any widget, you bind to the <Configure> event sent to that widget and use the %w and %h to get the width and height that the widget is being set to. (Indeed, geometry managers like grid and pack work exactly like that internally, except they use C-level bindings and not script-level ones.)
bind $canvas <Configure> {adjustCanvasDimensions %W %w %h}
bind $frame <Configure {adjustFrameDimensions %W %w %h}
proc adjustCanvasDimensions {theCanvas width height} {
set theFrame $theCanvas.frame
set oldwidth [$theFrame cget -width]
if {$width != $oldwidth} {
$theFrame configure -width $width
}
# Consider adjusting the frame height if canvas height greater
}
proc adjustFrameDimensions {theFrame width height} {
set theCanvas [winfo parent $theFrame]
$theCanvas configure -bbox [list 0 0 $width $height]
}
Or something like that. This is untested code (and assumes you put the frame in the canvas, etc.) but ought to show you the way forward.

Rounded box in SSRS

I have rectangle which act as container for other elements.
Can I somehow setup some property of rectangle to round its corners, in fact, to get rounded box.
In css it is easy, but how to do in SSRS?
Actually, it is fairly easy. I had a bunch of text boxes that a rounded corner border needed to be placed. The first thing I tried was an image control. I placed it on top of my text boxes and set it to "Send to back." It worked well in print rendering, however, in the browser rendering the HTML placed the textboxes after the image making it look horrible.
The solution was this:
Go into paint and draw a rounded corner box the size you need.
Cut the set of text boxes to surround with rounded border.
Place a rectangle control over the entire area all the text boxes covered.
Paste my text boxes onto the rectangle.
Right-Click and choose rectangle properties.
Select the Fill Tab and select "Embedded" image source.
Click Import and select your paint image(i used PNG but it shouldn't matter).
Click Ok.
Find and expand BackgroundImage on Rectangle and change BackgroundRepeat to "Clip.". Otherwise, your image is repeated.
The report should now render properly in both print and html rendering views. Unfortunately, this doesn't seem to stretch/size, so unless you can figure that one out, you will have to repeat whenever you need a different sized rounded box.
Brian
All solution I have seen use a background image inside a textbox.
But you get problems when you try to resize the textbox.
The solution is to insert a 3x3 table inside the texbox.
Insert the 3x3 table
Insert an image on each corner. They will be a quarter of a circle each. (This image is created in MS Paint or your favorite image program)
Make those 4 corners cells unresizable (Set property CanGrow to false). Make sure all the other cells have CanGrow = true if you need it
Make all the cells the same background color (same color as the image you draw).
Write your text in the middle cell.
OPTIONAL: It might also be a good idea to fuse the 3 vertical middle cells if possible. It will allow more space to write text in the cell.
This way you won't have to create new image everytime the size of your textbox change.
You would have to build an image that has a transparent center for adding your text.
All this would be more work than I would want to do just for a report.
I would stick with just the standard textboxes.

Tabs Vertical? (Tabbed View)

I'm trying to make the tabs in TabbedViewNavigatorApplication and ViewNavigator line up vertically instead of the original horizontal.
To be able to manipulate the tabBar I've followed this guide: http://devgirl.org/2011/06/14/flex-4-5-mobile-development-tabs-on-top/
I've managed to, via the guide, place the tabBar at the top of the screen.
So now the last thing left to do, how do I align the tabs vertical? I wan't one tab per row, as if they were buttons lying in a VGroup.
Should I use any kind of rotation to turn the tabBar 90 degrees or can I align the Tabs vertically? Should I manipulate the "TabbedViewNavigatorSkin" or in the TabbedViewNavigatorApplication.
How I want it to look: (picture has been Photoshopped for show)
http://imageshack.us/a/img96/2461/1234yl.jpg
Thanks
take the TabbedViewNavigatorSkin and modify it. if you are lucky, its just a matter of providing the layout orientation from horizontal to vertical