Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 更改Tk窗口上的标题栏_Python_Tkinter_Titlebar - Fatal编程技术网

Python 更改Tk窗口上的标题栏

Python 更改Tk窗口上的标题栏,python,tkinter,titlebar,Python,Tkinter,Titlebar,我试着让我的Tk窗口的顶部栏说Tk的计算器安装在那里无论如何都可以这样做,我也可以把它旁边的小图标换成不同的图像,如果不是的话,标题就可以了谢谢 代码如下: import math def calculate(): try: num1 = float(enter1.get()) num2 = float(enter2.get()) result = num1 * num2 label3.config(text=str(re

我试着让我的Tk窗口的顶部栏说Tk的计算器安装在那里无论如何都可以这样做,我也可以把它旁边的小图标换成不同的图像,如果不是的话,标题就可以了谢谢

代码如下:

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()
导入数学
def calculate():
尝试:
num1=float(enter1.get())
num2=float(enter2.get())
结果=num1*num2
label3.config(text=str(结果))
除值错误外:
label3.config(text='Enter numeric values!')
def calculate2():
尝试:
num1=float(enter1.get())
num2=float(enter2.get())
结果=num1/num2
label3.config(text=str(结果))
除值错误外:
label3.config(text='Enter numeric values!')
def calculate3():
尝试:
num1=float(enter1.get())
num2=float(enter2.get())
结果=num1+num2
label3.config(text=str(结果))
除值错误外:
label3.config(text='Enter numeric values!')
def calculate4():
尝试:
num1=float(enter1.get())
num2=float(enter2.get())
结果=num1-num2
label3.config(text=str(结果))
除值错误外:
label3.config(text='Enter numeric values!',fg=“white”)
def calculate5():
尝试:
num1=float(enter1.get())
结果=num1**2
label3.config(text=str(结果))
除值错误外:
label3.config(text='Enter numeric values!',fg=“white”)
def calculate6():
尝试:
num1=float(enter1.get())
结果=math.sqrt(num1)
label3.config(text=str(结果))
除值错误外:
label3.config(text='Enter numeric values!',fg=“white”)
root=Tk()
root.configure(background='black')
label1=标签(根,text='First Number:',bg=“黑色”,fg=“白色”)
标签1.网格(行=0,列=0,列span=2)
enter1=条目(根,bg='white')
输入1.grid(行=1,列=0,列span=2)
label2=标签(根,text='第二个数字:',bg=“黑色”,fg=“白色”)
label2.grid(行=2,列=0,列span=2)
enter2=条目(根,bg='white')
输入2.grid(行=3,列=0,列span=2)
btn1=按钮(根,文本='-Multiply-',命令=计算,bg=“黑色”,activebackground=“绿色”,fg=“白色”)
btn1.网格(行=4,列=0)
btn2=按钮(根,文本='-Divide-',命令=calculate2,bg=“黑色”,activebackground=“橙色”,fg=“白色”)
btn2.网格(行=5,列=0)
btn3=按钮(根,文本='-Add-',命令=calculate3,bg=“黑色”,activebackground=“紫色”,fg=“白色”)
btn3.网格(行=5,列=1)
btn4=按钮(根,文本='-Subtract-',命令=calculate4,bg=“黑色”,activebackground=“红色”,fg=“白色”)
btn4.网格(行=4,列=1)
btn5=按钮(根,text='Square(仅第一个),command=calculate5,bg=“black”,activebackground=“cyan”,fg=“white”)
btn5.网格(行=6,列=0,列跨度=2)
btn6=按钮(根,text='平方根(仅第一个),command=calculate6,bg=“黑色”,activebackground=“黄色”,fg=“白色”)
btn6.网格(行=7,列=0,列span=2,)
label3=标签(根,bg=“黑色”)
标签3.网格(行=8,列=0,列span=2)
输入1.focus()
enter1.bind(“”,func=lambda e:enter2.focus\u set())
root.mainloop()
像这样:

root.title("My Application Title")
可在中找到更改图标的方法