更改 Tk 窗口上的标题栏 [英] Change Title Bar on a Tk window

查看:46
本文介绍了更改 Tk 窗口上的标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的 Tk 窗口的顶部栏说 Tk 的计算器 instaed 无论如何都可以这样做,我也可以将旁边的小图标更改为不同的图像,如果不是标题就好了谢谢

Im trying to make the top bar of my Tk window say calculator instaed of Tk is there anyway to do that also can i change the little icon beside it to a differnt image if not the title would just be fine Thank you

代码如下:

import math

def calculate():
    try:
        num1 = float(enter1.get())
        num2 = float(enter2.get())
        result = num1 * num2
        label3.config(text=str(result))
    except ValueError:
        label3.config(text='Enter numeric values!')
def calculate2():
    try:
        num1 = float(enter1.get())
        num2 = float(enter2.get())
        result = num1 / num2
        label3.config(text=str(result))
    except ValueError:
        label3.config(text='Enter numeric values!')
def calculate3():
    try:
        num1 = float(enter1.get())
        num2 = float(enter2.get())
        result = num1 + num2
        label3.config(text=str(result))
    except ValueError:
        label3.config(text='Enter numeric values!')
def calculate4():
    try:
        num1 = float(enter1.get())
        num2 = float(enter2.get())
        result = num1 - num2
        label3.config(text=str(result))
    except ValueError:
        label3.config(text='Enter numeric values!',fg="white")
def calculate5():
    try:
        num1 = float(enter1.get())
        result = num1**2
        label3.config(text=str(result))
    except ValueError:
        label3.config(text='Enter numeric values!',fg="white")
def calculate6():
    try:
        num1 = float(enter1.get())
        result = math.sqrt(num1)
        label3.config(text=str(result))
    except ValueError:
        label3.config(text='Enter numeric values!',fg="white")



root = Tk()
root.configure(background='black')



label1 = Label(root, text='First Number:',bg="black", fg="white")
label1.grid(row=0, column=0,columnspan=2)
enter1 = Entry(root, bg='white')
enter1.grid(row=1, column=0,columnspan=2)


label2 = Label(root, text='Second Number:',bg="black", fg="white")
label2.grid(row=2, column=0,columnspan=2)
enter2 = Entry(root, bg='white')
enter2.grid(row=3, column=0, columnspan=2)



btn1 = Button(root, text='-Multiply-', command=calculate,               bg="black",activebackground="green", fg="white")
btn1.grid(row=4, column=0)
btn2 = Button(root, text='-Divide-', command=calculate2,     bg="black",activebackground="orange", fg="white")
btn2.grid(row=5, column=0)
btn3 = Button(root, text='-Add-', command=calculate3,  bg="black",activebackground="purple", fg="white")
btn3.grid(row=5, column=1)
btn4 = Button(root, text='-Subtract-', command=calculate4,  bg="black",activebackground="red", fg="white")
btn4.grid(row=4, column=1)
btn5 = Button(root, text='Square (Only First #)', command=calculate5,    bg="black",activebackground="cyan", fg="white")
btn5.grid(row=6, column=0, columnspan=2)
btn6 = Button(root, text='Square Root (only First #)', command=calculate6,  bg="black",activebackground="yellow", fg="white")
btn6.grid(row=7, column=0, columnspan=2,)
label3 = Label(root, bg="black")
label3.grid(row=8, column=0, columnspan=2)


enter1.focus()

enter1.bind('<Return>', func=lambda e:enter2.focus_set())

root.mainloop()

推荐答案

像这样:

root.title("My Application Title")

更改图标的方法可以在这个答案中找到.

The method for changing the icon can be found in this answer.

这篇关于更改 Tk 窗口上的标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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