So I found tutorial about work with GUI in python tkinter
then I try to learn it from w3school, I copied the sample code:
from tkinter import *
from tkinter .ttk import *
root = Tk()
label = Label(root, text="Hello world Tkinket GUI Example ")
label.pack()
root.mainloop()
So, I google how to install tkinter on ubuntu.
I used:
$ sudo apt-get install python-tk python3-tk tk-dev
$ sudo apt-get install python-tk
$ pip install tk
It’s seem it was successfully but I was wrong..
I get this error
Ubuntu 22.04.1 LTS
3
Answers
I believe you only need to use:
from tkinter import *
I’d say get rid of the:
from tkinter .ttk import *
I think you can just remove the line:
from tkinter .ttk import *
I don’t think you need that line to run this code.
Generally what you want is
I know star imports have a certain appeal, but they can lead to namespace pollution which is a huge headache!
For example lets say I’ve done the following:
is
Label
a tkinter widget or a ttk widget?Conversely…
Here, it’s clear that
label
is a ttk widget.Now everything is namespaced appropriately, and everyone’s happy!