-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_vs_from_import.py
More file actions
53 lines (40 loc) · 1.32 KB
/
import_vs_from_import.py
File metadata and controls
53 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'''
This just launches a basic Window / GUI. Decided to save this piece because it
illustrates a subtle but important difference between import and from import.
'''
import tkinter
#from tkinter import *
# The Window class is not standard - create a window
class Window(tkinter.Frame):
def __init__(self, master=None):
tkinter.Frame.__init__(self, master)
self.master = master
# initialize tkinter
root = tkinter.Tk()
app = Window(root)
# set window title
root.wm_title("Tkinter window")
# show window
root.mainloop()
'''
This code below will work but, compared with code above demonstrates import-ant (eh? eh?)
differences between 'import tkinter' and 'from tkinter import *'
The first one (import) creates a reference to that module, which is why the objects then
need to be qualified with tkinter dot whatever.
The second one (from ... import *) creates a reference to all of that module's public
objects within the local namespace of the current module - big difference.
'''
'''
from tkinter import *
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
# initialize tkinter
root = Tk()
app = Window(root)
# set window title
root.wm_title("Tkinter window")
# show window
root.mainloop()
'''