#Why dont my python GUI work?

21 messages · Page 1 of 1 (latest)

ebon ruin
#

import tkinter as tk

window = tk.Tk()

greetings = tk.Label(text="works")

button = tk.Button(
text="Click me!",
width=25,
height=5,
bg="blue",
fg="yellow",
)

window.mainloop()

woven agate
#

You need to position the things you are creating on the window

#

greeting.pack() for example

ebon ruin
#

and it also shows " keyword argument repeated : text"

ebon ruin
woven agate
#

You need to position your labels and buttons on the window. It might be a good idea to follow a tutorial. https://realpython.com/python-gui-tkinter/

In this tutorial, you'll learn the basics of GUI programming with Tkinter, the de facto Python GUI framework. Master GUI programming concepts such as widgets, geometry managers, and event handlers. Then, put it all together by building two applications: a temperature converter and a text editor.

ebon ruin
#

but the button is still not working

woven agate
#

You also need to position the button

#

button.pack()

#

There are more options available if you keep following the tutorial
https://realpython.com/python-gui-tkinter/#controlling-layout-with-geometry-managers

In this tutorial, you'll learn the basics of GUI programming with Tkinter, the de facto Python GUI framework. Master GUI programming concepts such as widgets, geometry managers, and event handlers. Then, put it all together by building two applications: a temperature converter and a text editor.

ebon ruin
woven agate
#

pack is a general thing for widgets but maybe it could be clearer yeah. Any widget needs to be placed on the screen using one of the methods in the link above

ebon ruin
#

Can we make modern looking GUIs with tkinter?

woven agate
#

If you do from tkinter import ttk and then use ttk.Button for example then it should look a bit more "modern"

#
from tkinter import *
from tkinter import ttk
root = Tk()
frm = ttk.Frame(root, padding=10)
frm.grid()
ttk.Label(frm, text="Hello World!").grid(column=0, row=0)
ttk.Button(frm, text="Quit", command=root.destroy).grid(column=1, row=0)
root.mainloop()

Here is an example from the docs showing what the imports should look like
https://docs.python.org/3/library/tkinter.html

ebon ruin
#

looks same, but I'll eventually get there

woven agate
#

Yeah that's as "modern" as you are going to get with tkinter

ebon ruin
#

@woven agate Thanks