From: Jesus Jesus <jesussalas187 / hotmail.com>
Subject: tkToplvel remove close,restore and minimize buttons
Date: Sun, 29 Mar 2009 04:39:31 +0900
Message-ID: <7212f8602e9c8ec2fc49434282afcba6 / ruby-forum.com>
> i need to remove close,restore and minimize buttons from tk toplevel

For example, 
-------------------------------------------
require 'tk'
top = TkToplevel.new{
    overrideredirect true
    geometry '200x150+200+200'
}

#top.withdraw.deiconify 
#^^^^^^^^^^^^^^^^^^^^^^
# Sometimes, this line is required to remove the frame 
# decorated by the window manager.

TkButton.new(top, :text=>'close', :command=>proc{top.destroy}).pack(:pady=>20)
TkButton.new(top, :text=>'exit', :command=>proc{exit}).pack(:pady=>20)
Tk.mainloop
-------------------------------------------
or
-------------------------------------------
require 'tk'
TkToplevel.new(:overrideredirect=>true, 
               :geometry=>'200x150+200+200'){|top|
  TkButton.new(top, :text=>'close', :command=>proc{top.destroy}).pack(:pady=>20)
  TkButton.new(top, :text=>'exit', :command=>proc{exit}).pack(:pady=>20)
}
Tk.mainloop
-------------------------------------------

However, when remove the window manager's frame, 
you cannot move the toplevel window by mouse.
If you need to do that, you have to make bindings to control the toplevel.

The following is a sample of "Non-rectangle window" (Windows only).
------------------------------------------------------------------------
require 'tk'

TRANS_COLOR = '#020202'  # Transparent color.
                         # Of course, any color is available which is
                         # not used at non-transparent part. 

root = Tk.root.title('Non-rectangle and half-transparent window demo')

root.overrideredirect = true
root.attributes(:transparentcolor=>TRANS_COLOR) # set transparent color

x = 300
y = 200

# color = '#66bb88'
color = 'DarkSeaGreen'

root.attributes(:alpha=>0.75)  # alpha setting (half-transparent setting)
                               # 0.0 (full trans) 〜 1.0 (non trans)

# In this script, use a canvas widget as a base frame. 
# One of the other ways is a label widget with a photo-image. 
c = TkCanvas.new(root, :width=>x, :height=>y,
                 :highlightthickness=>0,
                 :background=>TRANS_COLOR).pack

# draw a figure which is a frame of non-rectangle window.
ov = TkcOval.new(c, [0,0], [x,y], :outline=>color, :fill=>color)

# place buttons (Only demo use. Those have no callback function.)
TkcWindow.new(c, [200, 50],  :window=>TkButton.new(:text=>'button1'))
TkcWindow.new(c, [150, 100], :window=>TkButton.new(:text=>'button2'))
TkcWindow.new(c, [100, 150], :window=>TkButton.new(:text=>'button3'))

# binding to toggle the window frame of the window manager.
# It may looks complex. 
# The reason of the complexity is to control the window position 
# to avoid sliding of the window when toggle the window frame.
c.bind('Double-1'){
  if root.overrideredirect
    # with no window frame
    rx = c.winfo_rootx; ry = c.winfo_rooty
    root.overrideredirect = false
    root.attributes(:transparentcolor=>nil) # 透過色の解除
    # root.withdraw; root.deiconify  # if X Window System
    /^(\d+)x(\d+)\+(-?\d+)\+(-?\d+)$/ =~ root.geometry
    xpos = $3.to_i; ypos = $4.to_i
    dx = c.winfo_rootx - rx; dy = c.winfo_rooty - ry
    root.geometry("+#{xpos - dx}+#{ypos - dy}")
  else
    # with a window frame
    /^(\d+)x(\d+)\+(-?\d+)\+(-?\d+)$/ =~ root.geometry
    xpos = $3.to_i; ypos = $4.to_i
    rx = c.winfo_rootx; ry = c.winfo_rooty
    root.overrideredirect = true
    root.attributes(:transparentcolor=>TRANS_COLOR) # 透過色の設定
    # root.withdraw; root.deiconify  # if X Window System
    root.geometry("+#{rx}+#{ry}")
  end
}

# bindings to drag the window
mark_px = mark_py = 0
mark_geom_x = mark_geom_y = 0
c.bind('1'){
  /^(\d+)x(\d+)\+(-?\d+)\+(-?\d+)$/ =~ root.geometry
  mark_geom_x = $3.to_i; mark_geom_y = $4.to_i
  mark_px, mark_py = c.winfo_pointerxy
}
c.bind('B1-Motion'){
  x, y = c.winfo_pointerxy
  root.geometry("+#{mark_geom_x + x - mark_px}+#{mark_geom_y + y - mark_py}")
}


# start eventloop
Tk.mainloop
------------------------------------------------------------------------
-- 
Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)