Tkinter-如何更改标题?

时间:2018-12-20 21:43:22

标签: python user-interface tkinter

我如何为此更改标题,我尝试用我所知道的方法,但无法正常工作。 只是让您知道代码是宏点击器

#from PIL import ImageGrab, ImageOps
import pyautogui
import time
import tkinter as tk
from numpy import *



class Coordinates():
#Coordinates can be changed to wherever you want to AutoClick
    replayBtn = (100,350)


# close button (woah)
class YourGUI(tk.Tk):
    def __init__(self):
        # inherit tkinter's window methods
        tk.Tk.__init__(self)

        tk.Label(self, text="ENTER X:").grid(row=0, column=3)
        self.inputX = tk.Entry(self)
        self.inputX.grid(row=0, column=1)

        tk.Label(self, text="ENTER Y:").grid(row=0, column=0)
        self.inputY = tk.Entry(self)
        self.inputY.grid(row=0, column=4)

        tk.Button(self, text="convert", command=self.do_conversion).grid(row=3, column=0, columnspan=2)

        tk.Button(self, text="exit!", command=self.EXITME).grid(row=4, column=0, columnspan=2)

    def EXITME(self):
        exit(0)  # crashed prog so it closes
        # strtoint("crashmE!")

    def do_conversion(self):
        y = self.inputY.get()
        x = self.inputX.get()

        running = True
        try:
            x = int(x)
            y = int(y)
        except:
            print("Invalid point")
            exit(0)
            # strtoint("crashmE!")
        while running:
            pyautogui.click(x, y)


your_gui = YourGUI()
your_gui.mainloop()

1 个答案:

答案 0 :(得分:0)

如果您用“ this”表示tkinter窗口的设置标题。您有几种选择。

选项1

if __name__ == '__main__':    
    your_gui = YourGUI()
    your_gui.title('My Title') # Set title
    your_gui.mainloop()

选项2

 def __init__(self):
        # inherit tkinter's window methods
        tk.Tk.__init__(self)
        self.title('My Title')  # Set title
        .......
        tk.Button(self, text="exit!", command=self.EXITME).grid(row=4, column=0, columnspan=2)

两个选项都应在Python 3.7.1和Python 2.7.5中工作