I'm printing the current time by pressing the Python tkinter button, but why can't I print the GUI button?

Asked 2 years ago, Updated 2 years ago, 72 views

If you click the button with the TKINTER GUI, the current time is printed, but the button is not printed in the 23rd and 3rd positions.

There are no errors.

What's the problem?

from datetime import datetime
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
import webbrowser


class MyInformation:
    def __init__(self):
        self.root = Tk()

    def Button_Clicked(self): # Current visual output function
        now = datetime.now()
        print("now date and time : "+str(now))

        button = Button (self.root, text="current visual output", command=self.Button_Closed, width=10, height=2)
        self.button.grid(row=23, column=3)
        self.root.mainloop()

python gui tkinter

2022-09-20 21:48

2 Answers

from tkinter import *
from datetime import datetime

# import matplotlib.pyplot as plt
# from matplotlib.figure import Figure
# from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
# import webbrowser


class MyInformation:
    def __init__(self):
        self.root = Tk()

        Self button = button (self text, root button clicked,. = = "It's now output" ; command self width 2 = 10, height).
        self.button.grid(row=23, column=3)
        self.label = Label(self.root, text="", width=40, height=2)
        self.label.grid(row=1, column=1)

    def button_clicked(self): # Current visual output function
        now = datetime.now()
        print("now date and time : " + str(now))
        self.label["text"] = "now date and time : " + str(now)

    def run(self):
        self.root.mainloop()


main = MyInformation()
main.run()


2022-09-20 21:48

You must create a class object. Variable = class.


2022-09-20 21:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.