防止 window 调整大小(R 中的 tcltk)
Prevent from window resizing (tcltk in R)
我在 R 中用 tcltk
包创建了一个 GUI window。window 看起来像这样:
当我将单选按钮添加到 window 或从中删除它们时(通过按按钮 "Add C" 或 "Del A"),window 会调整大小。
我如何防止这种行为并创建一个 window 可以包含五行单选按钮而不调整大小并且在我删除按钮时不调整大小。
我的代码:
library(tcltk)
library(tcltk2)
top <- tktoplevel()
# Create buttons
onEXIT <- function() {tkdestroy(top)}
onDELETE <- function() {tkdestroy(buttonA)}
onADD <- function() {tkgrid(buttonC)}
butOK <- tk2button(top, text = "Exit", command = onEXIT)
butADD <- tk2button(top, text = "Add C", command = onADD)
butDELETE <- tk2button(top, text = "Del A", command = onDELETE)
tkgrid(butOK, butDELETE, butADD)
# Create radiobuttons
buttonA <- tkradiobutton(top, text = "A")
buttonB <- tkradiobutton(top, text = "B")
buttonC <- tkradiobutton(top, text = "C")
tkgrid(buttonA)
tkgrid(buttonB)
解决方案很简单,使用 tkpack.propagate
。你的情况:
top <- tktoplevel()
tkpack.propagate(top, FALSE)
我在 R 中用 tcltk
包创建了一个 GUI window。window 看起来像这样:
当我将单选按钮添加到 window 或从中删除它们时(通过按按钮 "Add C" 或 "Del A"),window 会调整大小。
我如何防止这种行为并创建一个 window 可以包含五行单选按钮而不调整大小并且在我删除按钮时不调整大小。
我的代码:
library(tcltk)
library(tcltk2)
top <- tktoplevel()
# Create buttons
onEXIT <- function() {tkdestroy(top)}
onDELETE <- function() {tkdestroy(buttonA)}
onADD <- function() {tkgrid(buttonC)}
butOK <- tk2button(top, text = "Exit", command = onEXIT)
butADD <- tk2button(top, text = "Add C", command = onADD)
butDELETE <- tk2button(top, text = "Del A", command = onDELETE)
tkgrid(butOK, butDELETE, butADD)
# Create radiobuttons
buttonA <- tkradiobutton(top, text = "A")
buttonB <- tkradiobutton(top, text = "B")
buttonC <- tkradiobutton(top, text = "C")
tkgrid(buttonA)
tkgrid(buttonB)
解决方案很简单,使用 tkpack.propagate
。你的情况:
top <- tktoplevel()
tkpack.propagate(top, FALSE)