pythontkinter

How can I avoid using both "import" and "from import" on the same package?


I have a script that uses Tkinter:

import tkinter.messagebox
from tkinter import *
from tkinter.filedialog import askdirectory
from tkinter import ttk

I am mixing both import and from ... import. Is that OK? Is there another way so I do not mix them both?


Solution

  • most of the import statements aee ok, but you should change from tkinter import * to import tkinter or import tkinter as tk. PEP8 suggests that global imports should be avoided, and that is good advice.