Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cant add menu to main window

Status
Not open for further replies.

tiago251

Programmer
Aug 7, 2002
3
CH
Hello,

I created this menu from an example generated with
VisualTcl but there is a problem: I can't insert the menu
in the main window, I am obliged to create a new window (window2)
and to put the menu .window2.m61 in it.

I also don't want to use tools like "menubutton" or "iwidgets::menubar"
because they are not especially beautiful and don't look like other
Windows32 standards menus, unlike the one below.

Could someone help me please? I only would like to have one window with
the menu, not too!

#menuTest.tcl
#may, the 15th 2002

toplevel .window2 -class Toplevel -menu ".window2.m61"

wm minsize .window2 300 300

menu .window2.m61 -activeborderwidth 1 -borderwidth 1 -disabledforeground #a3a3a3 -selectcolor #b03060 -tearoff 1

.window2.m61 add cascade -menu ".window2.m61.men63" -label file
menu .window2.m61.men63 -activeborderwidth 1 -borderwidth 1 -disabledforeground #a3a3a3 -selectcolor #b03060 -tearoff 0
.window2.m61.men63 add cascade -menu ".window2.m61.men63.men64" -label {file cascade}
menu .window2.m61.men63.men64 -activeborderwidth 1 -borderwidth 1 -disabledforeground #a3a3a3 -selectcolor #b03060 -tearoff 0
.window2.m61.men63.men64 add command -command exit -label {exit 1}
.window2.m61.men63.men64 add command -command {#exit 2 command} -label {exit 2}

.window2.m61 add checkbutton -variable menuCheck -command exit -label {menu check}

.window2.m61 add cascade -menu ".window2.m61.men62" -label help
menu .window2.m61.men62 -activeborderwidth 1 -borderwidth 1 -disabledforeground #a3a3a3 -selectcolor #b03060 -tearoff 0
.window2.m61.men62 add command -command {#about 1 command} -label {about 1}
.window2.m61.men62 add command -command {#about 2 command} -label {about 2}

# ------- end of file here -----------------------------------------

Also, another question, when I mix a C program and a TCL script is there a way to hide
the "DOS" window that appears (I think it is tlc_init who launches the interpreter window)
and to keep only the GUI visible?

Thanks a lot for your answers!

Tiago
tiago251@netcourrier.com
 
Here is a working example with a menu on the main window.
Code:
  . config -menu .mb
  menu .mb -type menubar
  .mb add cascade -label File -underline 0 -menu .mb.file
  menu .mb.file -type normal -tearoff 0
  .mb add cascade -label Edit -underline 0 -menu .mb.edit
  .mb.file add command -label New -underline 0 -command cmdnew -accelerator Ctrl-n
  .mb.file add command -label Open -underline 0 -command cmdopen -accelerator Ctrl-o
  .mb.file add command -label Save -underline 0 -command cmdsave -accelerator Ctrl-s
  .mb.file add separator
  .mb.file add command -label Quit -underline 0 -command exit -accelerator Ctrl-x
  menu .mb.edit -type normal -tearoff 0
  pack [frame .main]
  pack [scrollbar .main.scroll -command { .main.text yview }] -side right -fill y
  pack [text .main.text -yscrollcommand { .main.scroll set }]
  bind .main.text <Control-n> cmdnew
  bind .main.text <Control-o> cmdopen
  bind .main.text <Control-s> cmdsave
  proc cmdnew {} { .main.text delete 0.1 end }
  proc cmdopen {}   {
    set fn [tk_getOpenFile]
    if {$fn != &quot;&quot;}     {
      set h [open $fn r]
      cmdnew
      while {![eof $h]} { .main.text insert end [gets $h]\n }
      close $h
    }
  }
  proc cmdsave {}   {
    set fn [tk_getSaveFile]
    if {$fn != &quot;&quot;}     {
      set h [open $fn w]
      set max [lindex [split [.main.text index end] .] 0]
      for {set i 1} {$i < $max} {incr i}       { puts $h [.main.text get $i.0 $i.end] }
      close $h
    }
  }

Good luck!

ulis
 
I think that all your difficulties lied in the first line:
. config -menu .mb

ulis
 
Yes that worked fine! thanks a lot! That was what I was looking for...
C ya!
Tiago
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top