2016-06-27 4 views
2

私は非常にPythonには新しく、どのように動作するかをテストするためにいくつかのことを試みることにしました。しかし、私はtkinterボタン上のテキストを2行の代わりにする方法を見つけることができませんでした。コードは次のとおりです。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() 

方法がわかっている場合はお知らせください。

答えて

2

私は質問を正しく理解したが、文字列に\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() 
関連する問題