Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
How to set WM_CLASS on TkRoot in ruby

I'm trying to set the 'WM_CLASS' attribute for my ruby tk application. I've tried several ways, but I think it should work like that:

TkRoot.new(class: 'Test')

But that will err with:

<internal:kernel>:18:in `class': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from /home/ben/.gem/ruby/3.0.0/gems/tk-0.4.0/lib/tk/root.rb:40:in `block in new'
    from /home/ben/.gem/ruby/3.0.0/gems/tk-0.4.0/lib/tk/root.rb:36:in `each'
    from /home/ben/.gem/ruby/3.0.0/gems/tk-0.4.0/lib/tk/root.rb:36:in `new'
    from examples/form.rb:19:in `initialize'
    from examples/form.rb:49:in `new'
    from examples/form.rb:49:in `<main>'

How to do it correctly?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tk (C api) is setting the the WM_CLASS values to the value of argv[0] which is the same as $0 in ruby. So to set WM_CLASS, one has to set $0 prior to requiring Tk. i.e.:

$0 = 'myWmClass'
require 'Tk'

# ... rest of the code follows here

This will set the application name (of WM_CLASS) to 'myWmClass' and the application class to 'MyWmClass' (so uppercase is forced here). If one wants to set the application name to something different, this can be done via Tk.appname('someFancyName') after requiring Tk. Note that even though Tk is required, the main window seems not to be created and so the newly created main window will have the correct appname right from the start. Also note, that using an uppercase string as application name may result in errors, as the official tk command reference states.

For any other toplevel window (besides the root window), WM_CLASS can be set on construction, e.i. TkToplevel.new(root, class: 'Toplevel'). Trying to do that on TkRoot will currently result in an exception. (It seems however to work in the python api.)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!