H KJ
H KJ

Reputation: 3

Python Tkinter window title

I'm a beginner in Python so most things of my code is probably questionable but I'm having a hard time understand how I can change the window name of my little tkinter calculator app I've been programming.

When I run my code, I can see the characters "tk" in the middle of the window in the window top frame. I've looked at a few examples but don't understand how I can apply that to my code. I'd like to replace "tk" with a string of my own choice.

Here's what I got:

#!/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()

Upvotes: 0

Views: 3435

Answers (1)

Phoenixo
Phoenixo

Reputation: 2113

Just this :

root.title("my new title")

Upvotes: 4

Related Questions