Newer
Older
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python
"""
TOPS software installer. This is written using the EasyGui.py python module
which is, for simplicity, included in this file
EasyGui provides an easy-to-use interface for simple GUI interaction
with a user. It does not require the programmer to know anything about
tkinter, frames, widgets, callbacks or lambda. All GUI interactions are
invoked by simple function calls that return results.
Documentation is in an accompanying file, easygui.txt.
WARNING about using EasyGui with IDLE
======================================
You may encounter problems using IDLE to run programs that use EasyGui. Try it
and find out. EasyGui is a collection of Tkinter routines that run their own
event loops. IDLE is also a Tkinter application, with its own event loop. The
two may conflict, with the unpredictable results. If you find that you have
problems, try running your program outside of IDLE.
Note that EasyGui requires Tk release 8.0 or greater.
"""
EasyGuiRevisionInfo = " version 0.72 2004-06-20"
# see easygui.txt for revision history information
__all__ = ['ynbox'
, 'ccbox'
, 'boolbox'
, 'indexbox'
, 'msgbox'
, 'buttonbox'
, 'integerbox'
, 'multenterbox'
, 'enterbox'
, 'choicebox'
, 'codebox'
, 'textbox'
, 'diropenbox'
, 'fileopenbox'
, 'filesavebox'
, 'passwordbox'
, 'multpasswordbox'
, 'multchoicebox'
]
import sys
try:
from Tkinter import *
except:
sys.exit('Python is NOT installed with Tkinter on this system')
if TkVersion < 8.0 :
print "\n" * 3
print "*"*75
print "Running Tk version:", TkVersion
print "You must be using Tk version 8.0 or greater to use EasyGui."
print "Terminating."
print "*"*75
print "\n" * 3
sys.exit(0)
rootWindowPosition = "+40+100"
#rootWindowPosition = "+300+200"
import string
DEFAULT_FONT_FAMILY = ("MS", "Sans", "Serif")
MONOSPACE_FONT_FAMILY = ("Courier")
DEFAULT_FONT_SIZE = 10
BIG_FONT_SIZE = 12
SMALL_FONT_SIZE = 9
CODEBOX_FONT_SIZE = 9
TEXTBOX_FONT_SIZE = DEFAULT_FONT_SIZE
import tkFileDialog
#-------------------------------------------------------------------
# various boxes built on top of the basic buttonbox
#-------------------------------------------------------------------
def ynbox(message="Shall I continue?", title=""):
"""Display a message box with choices of Yes and No.
The default is "Yes".
Returns returns 1 if "Yes" is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwise returns 0.
If invoked without a message parameter, displays a generic request for a confirmation
that the user wishes to continue. So it can be used this way:
if ynbox(): pass # continue
else: sys.exit(0) # exit the program
"""
choices = ["Yes", "No"]
if title == None: title = ""
return boolbox(message, title, choices)
def ccbox(message="Shall I continue?", title=""):
"""Display a message box with choices of Continue and Cancel.
The default is "Continue".
Returns returns 1 if "Continue" is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwise returns 0.
If invoked without a message parameter, displays a generic request for a confirmation
that the user wishes to continue. So it can be used this way:
if ccbox(): pass # continue
else: sys.exit(0) # exit the program
"""
choices = ["Continue", "Cancel"]
if title == None: title = ""
return boolbox(message, title, choices)
def boolbox(message="Shall I continue?", title="", choices=["Yes","No"]):
"""Display a boolean message box.
The default is the first choice.
Returns returns 1 if the first choice is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwise returns 0.
"""
if title == None:
if message == "Shall I continue?": title = "Confirmation"
else: title = ""
reply = buttonbox(message, title, choices)
if reply == choices[0]: return 1
else: return 0
def indexbox(message="Shall I continue?", title="", choices=["Yes","No"]):
"""Display a buttonbox with the specified choices.
Return the index of the choice selected.
"""
reply = buttonbox(message, title, choices)
index = -1
for choice in choices:
index = index + 1
if reply == choice: return index
#-------------------------------------------------------------------
# msgbox
#-------------------------------------------------------------------
def msgbox(message="Shall I continue?", title="", buttonMessage="OK"):
"""Display a messagebox
"""
choices = [buttonMessage]
reply = buttonbox(message, title, choices)
return reply
#-------------------------------------------------------------------
# buttonbox
#-------------------------------------------------------------------
def buttonbox(message="Shall I continue?", title="", choices = ["Button1", "Button2", "Button3"],fontSize = DEFAULT_FONT_SIZE,message2 = None):
"""Display a message, a title, and a set of buttons.
The buttons are defined by the members of the choices list.
Return the text of the button that the user selected.
"""
global root, __replyButtonText, __widgetTexts, buttonsFrame
if title == None: title = ""
if message == None: message = "This is an example of a buttonbox."
# Initialize __replyButtonText to the first choice.
# This is what will be used if the window is closed by the close button.
__replyButtonText = choices[0]
root = Tk()
root.protocol('WM_DELETE_WINDOW', denyWindowManagerClose )
root.title(title)
root.iconname('Dialog')
root.geometry(rootWindowPosition)
root.minsize(600, 400)
# ------------- define the frames --------------------------------------------
messageFrame = Frame(root)
messageFrame.pack(side=TOP, fill=BOTH)
buttonsFrame = Frame(root)
buttonsFrame.pack(side=BOTTOM, fill=BOTH)
# -------------------- place the widgets in the frames -----------------------
messageWidget = Message(messageFrame, text=message, width=len(message)*fontSize+4)
messageWidget.configure(font=(DEFAULT_FONT_FAMILY,fontSize))
messageWidget.pack(side=TOP, expand=YES, fill=X, padx='3m', pady='3m')
if message2:
messageWidget = Message(messageFrame, text=message2, width=len(message)*fontSize+4)
messageWidget.configure(font=(DEFAULT_FONT_FAMILY,DEFAULT_FONT_SIZE))
Loading full blame...