Python Forum
How to import entire module ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to import entire module ?
#1
I want to import entire module. I dont want to specify each function of that module i plan on using.
For example:
from tkinter import messagebox
How to import whole thing so that messagebox.showinfo("Title", "text") would work ?
Reply
#2
you can do from tkinter import * but in general star imports are considered BAD practice and should be avoided at all cost. For example they may cause name collisions. It's also much more difficult to read the code, e.g. one would not know from where messagebox comes from. Still you can see it often used in tkinter tutorials
the best approach would be to use alias, e.g. something like import tkinter as tk and then fully reference the objects and functions you want to use, e.g. tk.messagebox.showinfo("Title", "text")
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
from tkinter import *
messagebox.showinfo("Title", "Ok")
messagebox.askokcancel("Title","Ok Cancel")
messagebox.askyesnocancel("Title","Yes No Cancel")
This does not work unless i am very specific on what i import.
I tried
from tkinter import *
tkinter.messagebox.showinfo("Title", "Ok")
tkinter.messagebox.askokcancel("Title","Ok Cancel")
tkinter.messagebox.askyesnocancel("Title","Yes No Cancel")
Cant get it to work
Reply
#4
messagebox.py don't get imported into global namespace bye using *.
So this file work stand alone and need imported as:
from tkinter import messagebox
Then you don't need to worry about * Evil (that never should be used).
Reply
#5
I have 1 problem of using import module that: when i import a module with a few function i've created and i don't know how to insert the definition of that function like others in python's library so that i can see how it works every time when using it.
Reply
#6
Its not just mesagebox i want to import, i want to be able to call any function from tkinter library without the need to import each and every one of them i use.
How to import entire library and be able to just call functions instead of importing those functions in order to be able to call them ?
Thanks !
For example:
import tkinter
file = tkinter.filedialog.askopenfile()
print(file)
Why this doesnt work ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 2,974 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  How can import variable beteen classes in same module johnjh 1 1,912 Apr-19-2020, 09:41 PM
Last Post: deanhystad
  [Tkinter] need help using a returned value to import module Brave774 16 7,877 Jun-01-2018, 08:03 AM
Last Post: Brave774

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020