Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6005205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:22:03+00:00 2026-05-23T01:22:03+00:00

There is something wrong with the way I assemble my Tk windows (with R

  • 0

There is something wrong with the way I assemble my Tk windows (with R tcltk and tcltk2, under Win XP)

library(tcltk)
library(tcltk2)

expandTk <- function() {
  root  <- tktoplevel()
  # textbox with scroll bars
  textbox <- tk2frame(root)
  scr <- tkscrollbar(textbox, repeatinterval=5, command=function(...) tkyview(txt,...))
  txt <- tktext(textbox, bg="white", font="courier", wrap="word", yscrollcommand=function(...)tkset(scr,...))
  tkpack(txt, side="left", fill="both", expand=TRUE)
  tkpack(scr, side="right", fill="y")
  tkmark.set(txt,"insert","0.0")
  tkpack(textbox, fill="both", expand=TRUE)
  # status bar and size grip
  statusText <- tclVar("")
  f <- tk2frame(root, relief="sunken")
  l <- tk2label(f, textvariable=statusText)
  tkpack(l, side="left", pady=2, padx=5, expand=0, fill="x")
  tkpack(f, side="left", expand=1, fill="x", anchor="s")
  sg <- ttksizegrip(root)
  tkpack(sg, side="left", expand=0, anchor="se")
}

The window looks fine, but as soon as I resize it (ie make it smaller), the scrollbar and the statusbar disappears. I am quite sure that this is a user error, I have seen other Tk apps which resize properly, but I can not figure out which option I should use…

Any hint appreciated,
Karsten

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:22:03+00:00Added an answer on May 23, 2026 at 1:22 am

    That’s standard behavior for the Tk pack geometry manager. Here’s a relevant section of the pack man page:

    If the cavity should become too small to meet the needs of a slave then the
    slave will be given whatever space is left in the cavity. If the cavity shrinks
    to zero size, then all remaining slaves on the packing list will be unmapped from
    the screen until the master window becomes large enough to hold them again.

    So if you shrink the overall window to be smaller than the space requested for the text widget, you leave no space for the other widgets, and they get unmapped.

    The best solution is to use the grid geometry manager, instead of pack. Generally speaking, I find grid to be much easier to use and capable than pack anyway, although your mileage may vary. In particular, it eliminates the need for many superfluous frame widgets, which can simplify your code a lot.

    I think you can use something like this:

    expandTk <- function() {
      root  <- tktoplevel()
      # textbox with scroll bars
      textbox <- tk2frame(root)
      txt <- tktext(textbox, bg="white", font="courier", wrap="word", yscrollcommand=function(...)tkset(scr,...))
      scr <- tkscrollbar(textbox, repeatinterval=5, command=function(...) tkyview(txt,...))
      tkmark.set(txt,"insert","0.0")
    
      # Set up the geometry for the stuff inside the "textbox" frame.
    
      # The text and scrollbar widgets live on the same row.
      tkgrid(txt, scr)
    
      # The text widget should stick to all four sides of its parcel.
      tkgrid.configure(txt, sticky="nsew")
    
      # The scrollbar should stick to the top and bottom of its parcel, it need not stick to the
      # left and right.
      tkgrid.configure(scr, sticky="ns")
    
      # When the window is resized, we want surplus space to be allocated to the text widget,
      # which is in the top left corner of this frame.
      tkgrid.columnconfigure(textbox,0,weight=1)
      tkgrid.rowconfigure(textbox,0,weight=1)
    
      # status bar and size grip
      statusText <- tclVar("")
      l <- tk2label(root, textvariable=statusText,relief="sunken")
      sg <- ttksizegrip(root)
    
      # Set up the geometry for the stuff inside the "root" window.
    
      # First row is just the textbox frame...
      tkgrid(textbox)
    
      # Second row is the status label and the resize gadget
      tkgrid(l, sg)
    
      # The textbox widget should span 2 colums, and stick to all four sides of its parcel.
      tkgrid.configure(textbox,columnspan=2,sticky="nsew")
    
      # The status label should stick to all four sides of its parcel too
      tkgrid.configure(l,sticky="nsew")
    
      # The resize gadget should only stick to the bottom right of its parcel
      tkgrid.configure(sg,sticky="se")
    
      # When the window is resized, we want surplus space to go to the textbox frame (and from there
      # to the text widget itself, which it will do thanks to the grid weights we set up above).  The
      # textbox frame is in the top left corner of its parent window.
      tkgrid.columnconfigure(root,0,weight=1)
      tkgrid.rowconfigure(root,0,weight=1)
    }
    

    There’s some more information about using the grid geometry manager from R here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are methods calls really so slow or is there something wrong in my computer?
There's something wrong with my code or I'm just not understanding this fully. I
Is there something special about Safari for Windows and AJAX? In other words: Are
Is there something like the Python descriptor protocol implemented in other languages? It seems
Is there something like InstallShield that I can use for free?
Is there something like Python's getattr() in C#? I would like to create a
Is there something like a panel that I can use in a MFC application.
is there something like a Quickfix in Eclipse IDE available in VisualStudio 2008? Thanks,
Is there something similar to sprintf() in C#? I would for instance like to
Is there something like python's interactive REPL mode, but for Java? So that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.