Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.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 Tkinter窗口标题_Python_Tkinter - Fatal编程技术网

Python Tkinter窗口标题

Python Tkinter窗口标题,python,tkinter,Python,Tkinter,我是Python的初学者,所以我的大部分代码可能都有问题,但我很难理解如何更改我一直在编程的tkinter计算器应用程序的窗口名 当我运行我的代码时,我可以看到窗口顶部框的窗口中间的字符“Tk”。我看了一些例子,但不明白如何将其应用到我的代码中。我想用我自己选择的字符串替换“tk” 以下是我得到的: #!/usr/bin/env python3 import tkinter as tk root = tk.Tk() canvas1 = tk.Canvas(root, width = 400,

我是Python的初学者,所以我的大部分代码可能都有问题,但我很难理解如何更改我一直在编程的tkinter计算器应用程序的窗口名

当我运行我的代码时,我可以看到窗口顶部框的窗口中间的字符“Tk”。我看了一些例子,但不明白如何将其应用到我的代码中。我想用我自己选择的字符串替换“tk”

以下是我得到的:

#!/usr/bin/env python3
import tkinter as tk

root = tk.Tk()

canvas1 = tk.Canvas(root, width = 400, height = 300)
canvas1.pack()

#entry and label for value 1
entry1 = tk.Entry (root, width=30)
entry1.place(x=110, y = 80)
entry1Label = tk.Label(root, text="Number 1")
entry1Label.place(x=30, y = 80)

#entry and label for value 2
entry2 = tk.Entry (root, width=30)
entry2.place(x=110, y= 110)
entry2Label = tk.Label(root, text="Number 2")
entry2Label.place(x=30, y = 110)

#entry and label for sum
v = tk.StringVar()
v.set("Awaiting input...")
entry3 = tk.Entry (root, width=30, textvariable=v)
entry3.place(x=110, y=140)
sumLabel = tk.Label(root, text="Sum = ")
sumLabel.place(x=30, y=140)

#Calc functions
def calculatePlus():
    x1 = entry1.get() 
    x2 = entry2.get()
    try:
        value1 = int(x1)
        value2 = int(x2)               
    except ValueError:
        v.set("Make sure you are using numeric values")
    else:     
        sumValue = value1 + value2
        v.set(sumValue)

def calculateMinus():
    x1 = entry1.get() 
    x2 = entry2.get()
    try:
        value1 = int(x1)
        value2 = int(x2)               
    except ValueError:
        v.set("Make sure you are using numeric values")
    else:     
        sumValue = value1 - value2
        v.set(sumValue)

def calculateDivision():
    x1 = entry1.get() 
    x2 = entry2.get()
    try:
        value1 = int(x1)
        value2 = int(x2)               
    except ValueError:
        v.set("Make sure you are using numeric values")
    else:     
        sumValue = value1 / value2
        v.set(sumValue)

def calculateMultiply():
    x1 = entry1.get() 
    x2 = entry2.get()
    try:
        value1 = int(x1)
        value2 = int(x2)               
    except ValueError:
        v.set("Make sure you are using numeric values")
    else:     
        sumValue = value1 * value2
        v.set(sumValue)

#UI Buttons
buttonplus = tk.Button(text='+', command=calculatePlus)
buttonplus.place(x=130,y=190)
buttonminus = tk.Button(text='-', command=calculateMinus)
buttonminus.place(x=170,y=190)
buttondivide = tk.Button(text='/', command=calculateDivision)
buttondivide.place(x=210,y=190)
buttonmultiply = tk.Button(text='*', command=calculateMultiply)
buttonmultiply.place(x=250,y=190)

root.mainloop()
仅此而已:

root.title("my new title")

这回答了你的问题吗?