我对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()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句