gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:10:55 25 4
gpt4 key购买 nike

我是 python 的新手,我决定尝试做一些东西来测试它是如何工作的。但是我找不到一种方法让 tkinter 按钮上的文本代替 2 行。这是代码:

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()

关于python tkinter 应用程序在多行上使用相同的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38059394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com