Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

adding style

by spencoid (Acolyte)
on Jun 11, 2018 at 19:31 UTC ( #1216428=perlquestion: print w/replies, xml ) Need Help??
spencoid has asked for the wisdom of the Perl Monks concerning the following question:

I have been using various versions of TK for 20 years or so. I recently started writing scripts by starting with an example I found online. I have finally figured out the syntax to get what I want with most widgets but using this version (or whatever it is) I can not figure out how to configure things like color and font on any of the widgets. I have searched online for answers and nothing seems to help. He is a minimal test case. I just want to be able to give buttons background color active color etc etc and to have control over font type and size.
use strict; use Tkx; my $tol = 1; my $main_back_color = "#EDF8F8"; Tkx::wm_title(".", "OIML lookup"); Tkx::ttk__frame(".c", -padding => "8 2 1 1"); #.c->configure( -background => "$backcolor" ); #Tkx::ttk__frame(".c"); Tkx::grid( ".c", -column => 0, -row => 1, -sticky => "nwes"); Tkx::grid_columnconfigure( ".", 0, -weight => 1); Tkx::grid_rowconfigure(".", 0, -weight => 1); Tkx::ttk__button(".c.calc", -text => "Calculate", -command => sub {cal +culate();}); Tkx::grid(".c.calc", -column => 0, -row => 0, -sticky => "W"); Tkx::ttk__button(".c.clear", -text => "Clear", -command => sub {clear( +);}); Tkx::grid(".c.clear", -column => 1, -row => 0, -sticky => "W"); Tkx::ttk__button(".c.wiz", -text => "Wizzard", -command => sub {wizzar +d();}); Tkx::grid(".c.wiz", -column => 2, -row => 0, -sticky => "E"); Tkx::ttk__radiobutton(".c.rb5", -text => '.00005"',-variable=> \$tol, +-value=> 1); Tkx::grid(".c.rb5", -column => 2, -row => 1, -sticky => "E"); Tkx::ttk__radiobutton(".c.rb6", -text => '.0001"',-variable=> \$tol, - +value=> 2); Tkx::grid(".c.rb6", -column => 3, -row => 1, -sticky => "w"); Tkx::MainLoop();

Replies are listed 'Best First'.
Re: adding style
by spencoid (Acolyte) on Jun 12, 2018 at 01:44 UTC
    i figured out that it was the ttk version of widgits that has almost no configuration options so i got rid of all that. i don't know what ttk offers other than padding but i think i can live without it.

      G'day spencoid,

      [Disclaimer: I've done a fair amount of work with Tkx; however, I've not touched it in a year or so and don't have any of my code or notes to hand. The following is all from memory and may even be out-of-date: please check details for yourself.]

      The first 't' in 'ttk' stands for themed. The default theme is basically whatever your platform provides (either as standard or your own configuration). You can create your own themes for use with Tkx and the 'ttk' version of widgets.

      The Tkx documentation (amongst other things) has links to two tutorials which could be of interest to you.

      If you haven't already read this, you probably should. In particular, look at the Subclassing Tkx::widget section. I recommend you do this. It can be a fair bit of work up front but it's worth it in the end: get rid of that multitude of "Tkx::" namespace prefixes; no longer worry about whether to use "_", "__" or "___" (and don't wear out your underscore key having to type all of them); stop having to decide if a "g_*" or "m_*" method is appropriate; and, of course, write methods for big_red_button() or whatever it is you want. I really do recommend this!
      TkDocs - Tk Tutorial
      By default, this shows code examples in Perl, Tcl, Ruby and Python: you can filter that to just show Perl. See the Note on Coding Style — I wouldn't recommend cutting and pasting their code verbatim (I seem to recall that, after Subclassing Tkx::widget, and using oher features described in Tkx::Tutorial, I reduced their code by 50% or more). There's information throughout on styling your widgets; however, for the 'ttk' widgets, your main reference would be the Styles and Themes section.

      — Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1216428]
Approved by Discipulus
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2018-12-15 13:26 GMT
Find Nodes?
    Voting Booth?
    How many stories does it take before you've heard them all?

    Results (69 votes). Check out past polls.