Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.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_Text_Tkinter - Fatal编程技术网

python tkinter应用程序在多行上显示相同的文本

python tkinter应用程序在多行上显示相同的文本,python,text,tkinter,Python,Text,Tkinter,我对python非常陌生,我决定尝试制作一些东西来测试它是如何工作的。但是我找不到一种方法让tkinter按钮上的文本代替两行。代码如下: import tkinter as tk hoho = 0 def lul(): global hoho hoho = hoho + 1 print(hoho) class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__

我对python非常陌生,我决定尝试制作一些东西来测试它是如何工作的。但是我找不到一种方法让tkinter按钮上的文本代替两行。代码如下:

import tkinter as tk
hoho = 0
def lul():
    global  hoho
    hoho = hoho + 1
    print(hoho)
class Application(tk.Frame):

    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.pack()
        self.createWidgets()


def createWidgets(self):
    self.hi_there = tk.Button(self, fg="green")
    self.hi_there["text"] = "Pressing buttons is fun, isn't it?"
    self.hi_there["command"] = self.lel
    self.hi_there.pack(side="top")

    def lel(self):
        lul()
root = tk.Tk()
app = Application(master=root)
app.mainloop()

如果你知道路,请告诉我

我希望我正确理解了这个问题,但是您可以在字符串中使用
\n
在按钮的新行上打印文本

import tkinter as tk
hoho = 0

def lul():
    global  hoho
    hoho = hoho + 1
    print(hoho)


class Application(tk.Frame):

    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.pack()
        self.createWidgets()


    def createWidgets(self):
        self.hi_there = tk.Button(self, fg="green")
        self.hi_there["text"] = "Pressing buttons\n is fun, isn't it?"
        self.hi_there["command"] = self.lel
        self.hi_there.pack(side="top")

    def lel(self):
        lul()


root = tk.Tk()
app = Application(master=root)
app.mainloop()