Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

291
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda