Here's the code to create a tkinter window of 300 width and 200 height, with a white background, text in the center, and an "OK" button to close the window:
main.py376 chars19 lines
In this code, we import the tkinter
package and create a new window using Tk()
. We set the title, size, and background color of the window using the title()
, geometry()
, and configure()
functions.
Next, we add a Label
widget to display the text "Hello, World!" in the center of the window, with some padding to make it look nicer. We pack the label into the window using the pack()
function.
Finally, we add an OK
button using a Button
widget. The command
parameter specifies that when the button is clicked, the destroy()
method of the window should be called to close the window. We pack the button into the window as well.
Finally, we start the event loop using the mainloop()
function to keep the window open and responsive to user events.
gistlibby LogSnag