Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Layout 删除按钮后调用布局管理器_Layout_Haskell_Button_Resize_Gtk2 - Fatal编程技术网

Layout 删除按钮后调用布局管理器

Layout 删除按钮后调用布局管理器,layout,haskell,button,resize,gtk2,Layout,Haskell,Button,Resize,Gtk2,我正在使用Haskell和gtk2hs绑定用GTK编写一个简单的计算器。 我正在尝试使用Glade实现一个基本/科学视图,就像在windows计算器中一样 我有一个GTKTable的按钮,但当我试图隐藏其中一些按钮时,按钮所在的位置会留下空白。要隐藏按钮,我将使用以下代码: bSqrt <- xmlGetWidget xml castToButton "bSqrt" widgetHide bSqrt bSqrt考虑使用和的嵌套组合以实现类似表格的效果。在“科学”按钮的VBox上调用wid

我正在使用Haskell和gtk2hs绑定用GTK编写一个简单的计算器。 我正在尝试使用Glade实现一个基本/科学视图,就像在windows计算器中一样

我有一个GTKTable的按钮,但当我试图隐藏其中一些按钮时,按钮所在的位置会留下空白。要隐藏按钮,我将使用以下代码:

bSqrt <- xmlGetWidget xml castToButton "bSqrt"
widgetHide bSqrt

bSqrt考虑使用和的嵌套组合以实现类似表格的效果。在“科学”按钮的VBox上调用
widgetHideAll
,将隐藏该列并根据需要刷新显示

import Control.Monad (forM_)
import Data.IORef as IORef
import qualified Graphics.UI.Gtk as Gtk

data Mode = Basic | Scientific

main = do
    Gtk.initGUI

    window <- Gtk.windowNew
    outerVbox <- Gtk.vBoxNew False 0

    -- Create a "table" of buttons as an HBox of VBoxes.
    hbox <- Gtk.hBoxNew True 5

    -- Load the "table" with dummy 'basic' buttons.
    forM_ [0..2] $ \i -> do
        vbox <- Gtk.vBoxNew False 5
        forM_ [0..2] $ \j -> do
            dummy <- Gtk.buttonNewWithLabel $ show (3*i+j :: Int)
            Gtk.boxPackStartDefaults vbox dummy
        Gtk.boxPackStartDefaults hbox vbox

    -- Load rightmost column with 'scientific' buttons.
    scibox <- Gtk.vBoxNew False 5
    forM_ [0..2] $ \j -> do
        dummy <- Gtk.buttonNewWithLabel $ "sci" ++ show (j :: Int)
        Gtk.boxPackStartDefaults scibox dummy
    Gtk.boxPackStartDefaults hbox scibox

    -- Begin in Scientific mode.
    let mode = Scientific
    modeRef <- IORef.newIORef mode

    -- Create a mode-toggling Button.
    button <- Gtk.buttonNewWithLabel $ getButtonText mode
    Gtk.on button Gtk.buttonActivated $
        toggleMode button modeRef scibox

    -- Pack the "table" and button vertically into window.
    Gtk.boxPackStartDefaults outerVbox hbox
    Gtk.boxPackStartDefaults outerVbox button
    Gtk.containerAdd window outerVbox

    -- Standard Gtk stuff.
    Gtk.onDestroy window Gtk.mainQuit
    Gtk.widgetShowAll window
    Gtk.mainGUI

getButtonText Basic = "Switch to Scientific"
getButtonText Scientific = "Switch to Basic"


toggleMode button modeRef scibox = do
    mode <- IORef.readIORef modeRef
    case mode of
        Basic -> do
            IORef.writeIORef modeRef Scientific
            Gtk.buttonSetLabel button $ getButtonText Scientific
            Gtk.widgetShowAll scibox
        Scientific -> do
            IORef.writeIORef modeRef Basic
            Gtk.buttonSetLabel button $ getButtonText Basic
            Gtk.widgetHideAll scibox
import-Control.Monad(表单)
将Data.IORef导入为IORef
将合格的Graphics.UI.Gtk导入为Gtk
数据模式=基本|科学
main=do
Gtk.initGUI

window考虑使用和的嵌套组合以实现类似表格的效果。在“科学”按钮的VBox上调用
widgetHideAll
,将隐藏该列并根据需要刷新显示

import Control.Monad (forM_)
import Data.IORef as IORef
import qualified Graphics.UI.Gtk as Gtk

data Mode = Basic | Scientific

main = do
    Gtk.initGUI

    window <- Gtk.windowNew
    outerVbox <- Gtk.vBoxNew False 0

    -- Create a "table" of buttons as an HBox of VBoxes.
    hbox <- Gtk.hBoxNew True 5

    -- Load the "table" with dummy 'basic' buttons.
    forM_ [0..2] $ \i -> do
        vbox <- Gtk.vBoxNew False 5
        forM_ [0..2] $ \j -> do
            dummy <- Gtk.buttonNewWithLabel $ show (3*i+j :: Int)
            Gtk.boxPackStartDefaults vbox dummy
        Gtk.boxPackStartDefaults hbox vbox

    -- Load rightmost column with 'scientific' buttons.
    scibox <- Gtk.vBoxNew False 5
    forM_ [0..2] $ \j -> do
        dummy <- Gtk.buttonNewWithLabel $ "sci" ++ show (j :: Int)
        Gtk.boxPackStartDefaults scibox dummy
    Gtk.boxPackStartDefaults hbox scibox

    -- Begin in Scientific mode.
    let mode = Scientific
    modeRef <- IORef.newIORef mode

    -- Create a mode-toggling Button.
    button <- Gtk.buttonNewWithLabel $ getButtonText mode
    Gtk.on button Gtk.buttonActivated $
        toggleMode button modeRef scibox

    -- Pack the "table" and button vertically into window.
    Gtk.boxPackStartDefaults outerVbox hbox
    Gtk.boxPackStartDefaults outerVbox button
    Gtk.containerAdd window outerVbox

    -- Standard Gtk stuff.
    Gtk.onDestroy window Gtk.mainQuit
    Gtk.widgetShowAll window
    Gtk.mainGUI

getButtonText Basic = "Switch to Scientific"
getButtonText Scientific = "Switch to Basic"


toggleMode button modeRef scibox = do
    mode <- IORef.readIORef modeRef
    case mode of
        Basic -> do
            IORef.writeIORef modeRef Scientific
            Gtk.buttonSetLabel button $ getButtonText Scientific
            Gtk.widgetShowAll scibox
        Scientific -> do
            IORef.writeIORef modeRef Basic
            Gtk.buttonSetLabel button $ getButtonText Basic
            Gtk.widgetHideAll scibox
import-Control.Monad(表单)
将Data.IORef导入为IORef
将合格的Graphics.UI.Gtk导入为Gtk
数据模式=基本|科学
main=do
Gtk.initGUI

窗口您使用的是什么布局管理器?也许你应该粘贴一些代码和说明来重现你的问题。我用的是Glade-3。我在上面添加了更多细节。我的布局很基本。VBox中有一个GTK表。我觉得我只是对GTK的基本知识一无所知。如何在运行时重新布局按钮?这在GTK中可能吗?
是否从工作中刷新
?它会更改窗口大小,但仍保留空间。这可能是因为按钮位于窗口内的GTK表中,而不是直接位于链接到的示例中的窗口中。我想我会放弃的,现在对我来说不值得花时间。非常感谢您的帮助,我非常感谢。在这种情况下,您可能需要从表容器中删除小部件并减少表中的列数。如果没有更具体的代码进行测试,就很难确定答案:与其他GUI代码一样,解决问题的方法是戳它,直到它达到您想要的效果。您使用的是什么布局管理器?也许你应该粘贴一些代码和说明来重现你的问题。我用的是Glade-3。我在上面添加了更多细节。我的布局很基本。VBox中有一个GTK表。我觉得我只是对GTK的基本知识一无所知。如何在运行时重新布局按钮?这在GTK中可能吗?
是否从工作中刷新
?它会更改窗口大小,但仍保留空间。这可能是因为按钮位于窗口内的GTK表中,而不是直接位于链接到的示例中的窗口中。我想我会放弃的,现在对我来说不值得花时间。非常感谢您的帮助,我非常感谢。在这种情况下,您可能需要从表容器中删除小部件并减少表中的列数。如果没有更具体的代码进行测试,就很难确定答案:与其他GUI代码一样,解决问题的方法是戳它,直到它达到您想要的效果。