如何更改操作系统栏中的 tkinter 默认标题? [英] How do I change tkinter default title in OS bar?

查看:33
本文介绍了如何更改操作系统栏中的 tkinter 默认标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Tkinter 编写一个 python 应用程序,但我找不到一种方法来更改操作系统顶部栏(Gnome 顶部栏和停靠栏)中的默认标题 Tk.我可以设置主窗口标题,但它不会更改顶部栏中保持 Tk 的字符串.老实说,我很惊讶我找不到任何人问同样的问题.

我正在使用 Python 3.6 在 Ubuntu 18.04 上开发

这是复制问题的示例代码:

导入 tkinter 作为 tk如果 __name__ == "__main__":主窗口 = tk.Tk()mainWindow.title("测试")mainWindow.geometry("1024x600")mainWindow.mainloop()

我希望在主窗口框架标题、操作系统顶部栏和操作系统应用程序停靠栏中读取字符串 TEST,但我只在 Windows 框架标题中得到它.其余显示Tk

解决方案

使用 className

mainWindow = tk.Tk(className='Ghanshyam')

根据 tkinter 上的 python 文档:><块引用>

Tk 类是在没有参数的情况下实例化的.这将创建 Tk 的顶级小部件,它通常是应用程序的主窗口.每个实例都有自己关联的 Tcl 解释器.

I am writing a python app using Tkinter and I cannot find a way to change the default title Tk in OS top bar (Gnome top bar and dock too). I can set the main window title but it does not change the string in the top bar where it stays Tk. Honestly I am surprised I cannot find anyone asking this same question.

I am developing on Ubuntu 18.04 using Python 3.6

This is a sample code to replicate the problem:

import tkinter as tk

if __name__ == "__main__":
    mainWindow = tk.Tk()
    mainWindow.title("TEST")
    mainWindow.geometry("1024x600")
    mainWindow.mainloop()

I would expect to read the string TEST in the main window frame title, in the OS top bar and in the OS application dock, but I get it only in the windows frame title. The rest display Tk

解决方案

Use className

mainWindow = tk.Tk(className='Ghanshyam')

According to python Docs on tkinter:

The Tk class is instantiated without arguments. This creates a toplevel widget of Tk which usually is the main window of an application. Each instance has its own associated Tcl interpreter.

这篇关于如何更改操作系统栏中的 tkinter 默认标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆