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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tk_dialog size 1

Status
Not open for further replies.

japskar

Programmer
Feb 13, 2002
27
0
0
I'm trying to insert a rather large line of text in a tk_dialog, but a tk_dialog can't expand to the size of my text. Instead, it wraps the text so that it fits inside a predefined textarea. Very annoying, because I have newline character at the end of each line.
Does anyone have a workaround for this?
I do need the local-grab and icon option, so placing my text in a "text" widget is not exactly what I want.

e.g.
tk_dialog .td {title} {this is a rather long line of text that has to fit in my tk_dialog without linewrapping} {} 0 {ok} {cancel} {try again}

best regards,
Jasper van Dijk
 
Why not create your own dialog?
Code:
proc dialog {w title text image default args} {
  toplevel $w
  wm title $w $title
  pack [label $w.l -text $text] -pady 20
  pack [frame $w.f] -pady 10 -padx 20
  set n 0
  foreach b $args   { 
    set cmd [format {set ::sel %s; destroy %s} $n $w]
    button $w.f.$n -text $b -command $cmd
    grid $w.f.$n -row 0 -column $n -padx 20
    incr n
  }
  vwait ::sel
  return $::sel
}

set rc [dialog .td {title} {this is a rather long line of text that has to fit in my tk_dialog without linewrapping} {} 0 {ok} {cancel} {try again}]
tk_messageBox -message "You pressed [lindex {{ok} {cancel} {try again}} $rc]"
(for simplification I don't used the image and default parameters)

ulis
 
Ha Ulis, you've been a great help again,
but please help me a little further in this puzzle.

You create a label and a frame in a toplevel; and in this frame you used a grid for placement of the buttons. A rather neat solution if I may say so.

Ok so far, but how can I point directly to an icon (which you left out for simplification)? Because I'd like a question- or error-icon on the left, just as in the tk_dialog. The first step is to create a frame and pack it on the left side of its parent. But then I've to fill it with a icon......and I don't know how.

-Jasper
 
Sorry but I don't how to use a dialog bitmap (as question or alert).
Here is a cheat: the image is created from scratch.
Code:
image create bitmap question -foreground gray50 -data "        #define dum_width 16        #define dum_height 24        static unsigned char dum_bits[] = {
    0xf0, 0x0f, 0xfc, 0x3f, 0xff, 0xff, 0x3f, 0xfc, 0x1f, 0xf8, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0,   
    0x00, 0xf0, 0x00, 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0x80, 0x0e, 0xc0, 0x03,
    0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03 
 };"
proc dialog {w title text image default args} {
  toplevel $w
  wm title $w $title
  pack [frame $w.f1] -pady 20
  pack [frame $w.f2] -padx 20
  grid [label $w.f1.i -image question] -row 0 -column 1 -padx 10
  grid [label $w.f1.l -text $text] -row 0 -column 2
  set n 0
  foreach b $args   { 
    set cmd [format {set ::sel %s; destroy %s} $n $w]
    button $w.f2.$n -text $b -command $cmd
    grid $w.f2.$n -row 1 -column $n -padx 20
    incr n
  }
  vwait ::sel
  return $::sel
}

set rc [dialog .td {title} {this is a rather long line of text that has to fit in my tk_dialog without linewrapping} question 0 {ok} {cancel} {try again}]
tk_messageBox -message "You pressed [lindex {{ok} {cancel} {try again}} $rc]"
If you have some .gif or .ppm images, you can do:
image create photo myimage -file myfile.gif


ulis
 
I got it!
Here is complete solution:
Code:
proc dialog {w title text bitmap default args} {
  toplevel $w
  wm title $w $title
  pack [frame $w.f1] -pady 20
  pack [frame $w.f2] -padx 20
  grid [label $w.f1.i -bitmap $bitmap] -row 0 -column 1 -padx 10
  grid [label $w.f1.l -text $text] -row 0 -column 2
  set n 0
  foreach key $args   { 
    set cmd [format {set ::sel %s; destroy %s} $n $w]
    set b $w.f2.$n
    button $b -text $key -command $cmd
    if {$n == $default}     { 
      $b config -default active 
      bind $w <Return> [list $b invoke]
    }
    grid $b -row 1 -column $n -padx 20
    incr n
  }
  vwait ::sel
  return $::sel
}

set rc [dialog .td {title} {this is a rather long line of text that has to fit in my tk_dialog without linewrapping} error 0 {ok} {cancel} {try again}]
tk_messageBox -message &quot;You pressed [lindex {{ok} {cancel} {try again}} $rc]&quot;

ulis
 
Ulis, you keep amazing me.

But thanks a lot for all the effort on this one.

Maybe they can put this solution in the next release of Tcl/tk (and call it tk_UlisDialog :) )


-Jasper
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top