Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda