2

I'm extremely new to python and I decided to try to make some things to test how things work. But I couldn't find a way to make a text on a tkinter button take the place of 2 rows. Here's the code:

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

If you know a way please let me know!

1 Answer 1

2

I hope I understood the question right but you can use \n in your string to print the text on a new line on the button.

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.