is there a way for me to link the movie file to the text in the listbox
Each listbox entry corresponds to a number, i.e. curselection returns the line number. You can link the number selected to a file using a dictionary.
is there a way for me to link the movie file to the text in the listbox
Each listbox entry corresponds to a number, i.e. curselection returns the line number. You can link the number selected to a file using a dictionary.
but I am unable to get the latest version to compile
What distro are you using as it is in most repositories.
You should eliminate the pass-through functions.
class DemoImpl(QtGui.QMainWindow):
def __init__(self, *args):
super(DemoImpl, self).__init__(*args)
uic.loadUi('K:\QTProjects\pos\mainwindow.ui', self)
self.btnLogin.clicked.connect(self.createConnection)
def createConnection(self):
db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName(':memory:')
if not db.open():
QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"), QtGui.qApp.tr("Unable to establish a database connection.\nThis example needs SQLite support. Please read the Qt SQL driver documentation for information how to build it.\n\nClick Cancel to exit."), QtGui.QMessageBox.Cancel)
return False
else:
QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"), QtGui.qApp.tr("Database Connected"), QtGui.QMessageBox.Cancel)
return True
find() will locate a character
found = 0
while found > -1:
found = text_to_output("\r")
You can then use split() and/or replace to create the modified output.
print text_to_output.split("\r")
but for some reason crashes with large numbers (the 10001st prime)
That is possibly the result of using "is". Python stores smaller numbers and points to them, so "is" works on smaller numbers since they all point to the same object, but once you get above the stored value it no longer works. This code works for me:
def nth_prime(n):
primes = [2]
test_int = 1
while len(primes) < n:
test_int += 2
prime_found = True
for p in primes:
if test_int % p == 0:
prime_found = False
break
if prime_found:
primes.append(test_int)
return primes[n - 1]
print( nth_prime(10002) )
"""
prints 104759 which is on the list here
http://www.cs.arizona.edu/icon/oddsends/primes.htm
I'm not going to count them to see if it really is number 10,002
"""
Take a look at Effbot's tutorial for an entry box to find out how you set and get the text as there are at least two ways to do it.
Also you are using "is" instead of equal. "is" tests for the same object, so can not be relied upon for an equal condition. Finally, the statement
else:
if p is primes[len(primes)]:
is unnecessary. The for loop takes care of that. So, you could use an indicator like this instead.
prime_found = True
for p in primes:
if test_int % p is 0:
prime_found = False
break
if prime_found:
primes.append(test_int)
##
##-------------------------------------------------------------------
## a short example of "is" vs. "=="
x = "abc"
y = "abcd"
print x is y, id(x), id(y) ## prints False
print x is y[:3], id(x), id(y) ## prints False
print x == y[:3], x, y[:3] ## prints True
The easiest way to do this is with a pass-through function.
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.opt1 = Button(frame, text="Opt1", command=self.opt_1)
self.opt1.pack(side=TOP)
self.opt2 = Button(frame, text="Opt2", command=self.opt_2)
self.opt2.pack(side=BOTTOM)
def opt_def(self, opt):
print 'You have choosen option', opt
def opt_1(self):
self.opt_def(1)
def opt_2(self):
self.opt_def(2)
root = Tk()
app = App(root)
root.mainloop()
The following slightly modified code displays correctly for me on a Slackware Linux system.
import Tkinter
def addmovie(root):
addboard = Tkinter.Toplevel()
addboard.title("Add a movie")
addboard.geometry("600x600")
#addboard(padx=10, pady=10)
print "add"
#adding the title
lbtitle = Tkinter.Label(addboard, text = "Enter the movie's title:")
lbtitle.grid(row = 1, column = 1)
entitle = Tkinter.Entry(addboard)
entitle.grid(row = 1, column = 3)
#adding the director
lbdirector = Tkinter.Label(addboard, text = "Enter the mmovie's director:")
lbdirector.grid(row = 2, column = 1)
endirector = Tkinter.Entry(addboard)
endirector.grid(row = 2, column = 3)
#adding the year
lbyear = Tkinter.Label(addboard, text = "Enter the movie's year:")
lbyear.grid(row = 3, column = 1)
enyear = Tkinter.Entry(addboard)
enyear.grid(row = 3, column = 3)
#if a value is left blank program will ask what to do
#to be added later
#The button and the commands to put it all together
btnok = Tkinter.Button(addboard, text = "Continue")
btnok.grid(row= 5, column = 4)
btncancel = Tkinter.Button(addboard, text = "Cancel", bg= 'red', command=root.quit)
btncancel.grid(row = 5, column = 1)
root = Tkinter.Tk()
addmovie(root)
root.mainloop()
The first thing you have to do is decide which GUI toolkit you wish to code for as you will have to move, or destroy/remove the original rectangle graphic and draw/display it in a different location depending on the toolkit. A pretty standard example using Tkinter:
import Tkinter as tk
import time
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=400)
canvas.pack()
# canvas.create_rectangle(x0, y0, x1, y1, option, ... )
# x0, y0, x1, y1 are corner coordinates of ulc to lrc diagonal
rc1 = canvas.create_rectangle(20, 260, 120, 360, outline='white', fill='blue')
rc2 = canvas.create_rectangle(20, 10, 120, 110, outline='white', fill='red')
for j in range(50):
y = x = 5
time.sleep(0.05)
canvas.move(rc1, x, -y)
canvas.move(rc2, x, y)
canvas.update()
root.mainloop()
Chance seldom interferes with the wise man; his greatest and highest interests have been, are, and will be, directed by reason throughout his whole life...Epicurus
fileStats = os.stat(files)
TypeError: Can't convert 'tuple' object to str implicitly
This says that "files" is tuple. Print "type(files)" and files itself if you want to on the line before the error.
It also doesn't seem to be part of the QTGui module either, even though the Class reference says it is.
If it is part of QtGui then you access it like this
QtGui.QFileDialog.getOpenFileName().
There has to be hundreds of examples on the web that you can copy as well.
I'm afraid that the runtime for the program will increase if I don't read the whole file to RAM
"I'm afraid" doesn't hold much water in the real world. Try reading the file both ways and see if there is a significant time difference.
First, do not read the entire file at one time, i.e. readlines(), instead:
for rec in open(file_name, "r"):
if key in mydictionary:
mydict[key]+=1
else:
mydictionary[key] = 1
If that doesn't help then you will have to switch an SQL file on disk. SQLite is simple to use for something like this so post back if you want some help.
I would suggest you first try substituting Destroy for Hide, and then check the docs for methods associated with widgets so you can think for yourself and make associations in the future. And mark the thread "Solved".
You should first test that the button is active, as you may be trying to delete a button that doesn't exits. So, a dictionary to store the button makes sense as you can look it up before trying to delete.
import wx
class Test:
def __init__(self):
app = wx.App(False)
frame = wx.Frame(None, wx.ID_ANY, "Test App")
panel = wx.Panel(frame)
vboxsizer = wx.BoxSizer(wx.VERTICAL)
self.grid = wx.GridSizer(rows=0, cols=3)
self.button_dict = {}
for j in range(5):
b = wx.Button(panel, label="Remove Button %d" % (j), id=j)
self.grid.Add(b)
b.Bind(wx.EVT_BUTTON, self.remove_button)
self.button_dict[j] = b
vboxsizer.Add(self.grid, 1, border=2, flag=wx.EXPAND|wx.ALL)
panel.SetSizer(vboxsizer)
frame.Show(True)
app.MainLoop()
def remove_button(self, e):
button_num = e.GetId()
print "ID =", button_num, type(button_num)
if button_num in self.button_dict:
self.button_dict[button_num].Hide()
if __name__ == "__main__":
t = Test()
This link is in "Similiar Threads" Create a Python Dictionary From a CSV File using CSV Module in Python
This is a simple dictionary with 'iamge' pointing to 'i am ge'. Most of the online tutorials cover dictionaries.
Generally speaking you open a new frame, not a new mainframe. There is no way to tell how the class is called from the sample, but you would access variables the same way as with any other class.
##--- Not tested
class Window_Test():
def __init__(self):
x=10
## instance of the class
fr = Frame_Test()
## call the function
y = fr.fn(x)
print "y =", y
print fr.var
return x
class Frame_Test():
def __init__(self):
self.var = "class Frame_Test variable"
def fn(self, x):
print "fn called -->", x
return x + 1
W=Window_Test()
Start with the second element and use index-1. Also, you should check for less than the first element as well as greater than the last element.
nums_list = [1,5,9,11,13,21,27,29,32]
for index in range(1, len(nums_list)):
if num > nums_list[index-1] and num < nums_list[index]:
## or
if nums_list[index-1] < num < nums_list[index]:
Only one for loop would be used because you want to access the same relative position in each string. Also, do not use "i" as a variable name as it looks too much like the number 1.
def cromo(a, b):
inc = 0
if len(a) != len(b):
print "both strings must be the same length"
return -1
for ctr in range(len(a)):
if a[ctr] != b[ctr]:
inc = inc + 1
print inc
return inc
A = "gtggcaacgtgc"
B = "gtagcagcgcgc"
print cromo(A, B)
I have no idea which output file you are talking about or which statement writes the header a second time. If you are talking about this segment of the code,
outfile = open(dst_file, "wb")
outfile.write(content)
outfile.close()
"wb" creates/overwrites to a new file each time the function is called. You can also replace a lot of this code with a list:
file_name_1 = "autotest-1"
file_name_2 = "checksum_files"
file_name_3 = "db_sql_scripts"
file_name_4 = "pokermanager_linux_install.rar"
file_name_5 = "windows_release"
file_name_6 = "windows_server"
main_url = "http://10.47.42.28:8080/cruisecontrol/artifacts/Poker-TTM_autotest_nightly_build/20101224200424/"
file1_re = re.compile(r"%s" % file_name_1)
file2_re = re.compile(r"%s" % file_name_2)
file3_re = re.compile(r"%s" % file_name_3)
file4_re = re.compile(r"%s" % file_name_4)
file5_re = re.compile(r"%s" % file_name_5)
file6_re = re.compile(r"%s" % file_name_6)
for link in get_links(main_url):
if file1_re.search(link["href"]):
DOWNLOAD_URL1 = "http://10.47.42.28:8080" + link["href"]
download(DOWNLOAD_URL1, DOWNLOAD_DST1)
if file2_re.search(link["href"]):
DOWNLOAD_URL2 = "http://10.47.42.28:8080" + link["href"]
download(DOWNLOAD_URL2, DOWNLOAD_DST2)
if file3_re.search(link["href"]):
DOWNLOAD_URL3 = "http://10.47.42.28:8080" + link["href"]
download(DOWNLOAD_URL3, DOWNLOAD_DST3)
if file4_re.search(link["href"]):
DOWNLOAD_URL4 = "http://10.47.42.28:8080" + link["href"]
download(DOWNLOAD_URL4, DOWNLOAD_DST4)
if file5_re.search(link["href"]):
DOWNLOAD_URL5 = "http://10.47.42.28:8080" + link["href"]
download(DOWNLOAD_URL5, DOWNLOAD_DST5)
if file6_re.search(link["href"]):
DOWNLOAD_URL6 = "http://10.47.42.28:8080" + link["href"]
download(DOWNLOAD_URL6, DOWNLOAD_DST6)
##-----------------------------------------------------------------------------
## replace all of this with the following (NOT TESTED)
##-----------------------------------------------------------------------------
file_list = ["autotest-1", "checksum_files", "db_sql_scripts", \
"pokermanager_linux_install.rar", "windows_release", "windows_server"]
DOWNLOAD_DST = ["name1", "name2", "name3", "name4", "name5", "name6"]
main_url = "http://10.47.42.28:8080/cruisecontrol/artifacts/"
main_url += "Poker-TTM_autotest_nightly_build/20101224200424/"
for link in get_links(main_url):
for ctr, file_name in enumerate(file_list):
file_re = re.compile(r"%s" % file_name)
if file_re.search(link["href"]):
DOWNLOAD_URL = "http://10.47.42.28:8080" + link["href"]
download(DOWNLOAD_URL, DOWNLOAD_DST[ctr])
Some print statements should clear up some things. And note that your __add__ function will yield an error but that is something to address after you get this part working.
class mylist:
def __init__(self,l):
self.data = l;
def __add__(self,l):
self.data = self.data + l
def __repr__(self):
return self.data
x = mylist([1,2,3])
print x
print x.data
#x = x + [4,5]
#print x
That is a fairly standard menu. An example only partially completed and tested.
import math
import sys
def get_number(func_name):
try:
arg = int(input("Enter number of degrees for function %s: " % func_name))
return arg
except:
print("Sorry, we can only calculate for integer degrees")
sys.exit(1)
def sin_funct():
name = "Sine"
val = get_number(name)
print("%s of %d is %f" % (name, val, math.sin(math.radians(float(val)))))
def cos_funct():
name = "Cosine"
val = get_number(name)
print("%s of %d is %f" % (name, val, math.cos(math.radians(float(val)))))
def tan_funct():
print "tan_funct called"
lookup = {
'1': "sin_funct()",
'sin': "sin_funct()",
'2': "cos_funct()",
'cos': "cos_funct()",
'3': "tan_funct()",
'tan': "tan_funct()"
}
a = raw_input("Enter 1 or sin, 2 or cos, 3 or tan: ").lower()[:3]
if a in lookup:
eval(lookup[a])
It is getting difficult to tell if something is a duplicate.
What always runs but never walks, often murmurs, never talks, has a bed but never sleeps, has a mouth but never eats?
Sorry, the power has been out for the last 2 days. Try something along these lines. I use vertical and horizontal boxes. There may be another way, but this is explicit and works for me. You should also place each horizontal+vertical box(es) in a separate function to make it easier to see what is going where.
import wx
class TestFrame ( wx.Frame ):
def __init__ ( self ):
wx.Frame.__init__ ( self, None, -1, 'wxPython' )
self.panel = wx.Panel ( self, -1 )
vbox = wx.BoxSizer(wx.VERTICAL)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
datepic = wx.DatePickerCtrl(self.panel, -1, size=(110, -1), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
choice_list = [' '+str(num) for num in range(1001,1100)]
print choice_list[0]
self.ch = wx.Choice(self.panel, -1, size=(100, 25), choices=choice_list)
self.ch.SetSelection(0)
hbox1.Add(datepic, 0, wx.ALL, 5)
hbox1.Add(self.ch, 0, wx.ALL, 5)
vbox.Add(hbox1, 0, wx.ALIGN_LEFT | wx.ALL, 5)
self.panel.SetSizer(vbox)
app = wx.App()
TestFrame().Show()
app.MainLoop()
The wiki at python.org is always a good place to start any search http://wiki.python.org/moin/WebFrameworks.
Effbot's example for reading a file into memory, which can then be written anywhere you like as long as the files are not huge.
import zipfile
file = zipfile.ZipFile("samples/sample.zip", "r")
for name in file.namelist():
data = file.read(name)
print name, len(data), repr(data[:10])
There is no reason to use a list, or if you do, don't create a new dictionary on every pass through the loop.
dict1={}
n=input("Enter the number of contacts : ")
for i in range(0,n):
name1=raw_input("Enter your name: ")
num=input("Enter your phone number: ")
if name not in dict1:
dict1[name] = num
else:
print name, "already on file...NOT added"
keys=dict1.keys()
keys.sort()
for k in keys: ## in name order
print dict1[k], k
C programmers don't like using "new" as there is a new keyword and an operator new in C++. They also insist on the redundant use of main(). Perhaps someone will write a "Python is not C" article. Until then, I will try to restrain from using variable names that make others uncomfortable. Hopefully, they will restrain from interrupting the program flow by making the reader jump back up into the program to find main() in order to start at the beginning, which is in the middle.
This stripped down version appears to work for me, but it is rewritten because it was too difficult to tell the i, l, and 1's apart, let alone what the variables with nonsense names are supposed to contain.
import wx
class TestFrame( wx.Frame ):
def __init__( self ):
wx.Frame.__init__ ( self, None, -1, 'wxPython' )
self.panel = wx.Panel ( self, -1 )
choice_list = [' '+str(num) for num in range(1001,1100)]
self.ch = wx.Choice(self, -1, size=(100, 25), choices=choice_list)
self.ch.SetSelection(0)
app = wx.App()
TestFrame().Show()
app.MainLoop()
Python does not have a keypress capture so you have to use one provided by the system like termios.
import termios, sys, os
TERMIOS = termios
def getkey():
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO
new[6][TERMIOS.VMIN] = 1
new[6][TERMIOS.VTIME] = 0
termios.tcsetattr(fd, TERMIOS.TCSANOW, new)
c = None
try:
c = os.read(fd, 1)
finally:
termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)
return c
if __name__ == '__main__':
print "type something...'q' to quit"
s = ''
while 1:
c = getkey()
if c == 'q':
break
print "captured key", c, ord(c)
s = s + c
print s
Or call a function that draws each square.
from graphics import *
def draw_square(win, points, color, change):
shape = Rectangle(Point(points[0], points[1]), Point(points[2], points[3]))
shape.setOutline(color)
shape.setFill(color)
shape.draw(win)
for j in range(2):
points[j] -= change
points[j+2] += change
width = 200
win = GraphWin("patch", width, width)
squares = 10
change = width/(squares*2) ## size change for each smaller square
points = [width, width, 0, 0] ## coordinates for the opposite corners
color = 0
color_list = ["red", "white"]
for j in range(squares):
draw_square(win, points, color_list[color], change)
color = [1,0][color]
raw_input("Press Enter")
It appears that the OP wants to open a web browser, i.e. subprocess.call("firefox"), and then submit some data after some period of time from a running program, which is beyond my knowledge. AFAIK you either do everything in the program or everything in the browser, especially if the page is changing.
In:
07:34 08:55 10 20
08:25 09:00 10 20
Out:
08:25 09:00 10 20
07:34 08:55 10 20
For a reverse order sort like this, you simply compare for greater instead of lesser, which Python sorts will do with the reverse=True parameter set. Do you also want to take into account the "10 20" which I assume is a date?
To start you off, look for redundant statements, like all of the if/elif at the end of the program that basically do the same thing. They can be replaced by a simple dictionary of values.
## The following 3 lines can be deleted for this example
#u = 1
#optimism = int(0)
#while (u != 0):
factor_dict = {"1": [0.862, 0.873],
"2": [0.951,0.965],
"3": [0.989,1.01],
"4": [1.022,1.036],
"5": [1.073,1.0827]}
optimism = ""
while optimism not in factor_dict:
optimism = raw_input(\
"""\nOn a scale of 1-5..
How Optimistic Do You Feel About The Remaining Grades?
Enter 1 if you plan to slack off.
Enter 2 if you're feeling somewhat pessimistic
Enter 3 if you're neutral.
Enter 4 if you're feeling good about the remainder.
Enter 5 if your grades are only going UP UP and AWAY!
I feel: """)
if optimism in factor_dict:
factor = random.uniform(factor_dict[0], factor_dict[1])
forecast = calc*factor/100
forecast *= grade_remain
forecast += ab
raw_input("Hit Enter To View Your Forecast.")
print "Your FORECASTED Grade is: ",forecast,"%"
else:
print "Please enter a value between 1-5."
It does not appear that you are using physical dimensions, since there are no numbers < 11, but this will print 5 random combinations.
import random
shapes = ['square', 'triangle', 'circle', 'left']
physical = range(1, 11)
angles = range(10, 91, 10)
print " shape phy angle"
for j in range(5):
print "%10s %2d %2d" % (random.choice(shapes), \
random.choice(physical), random.choice(angles))
This is a python forum. There are several forums on the open office site.
Add a little more to the print statements to tell you where you are.
def prime(n):
print "-"*30
print "starting prime with n =", n
if n == 0:
print("Equals zero, This is not a Prime number")
answer = 0
if n == 1:
print("Equals one, This is not a Prime number")
answer = 1
else:
val1 = n // prime(n - 1)
print "val1 = n // prime(n - 1)", val1
if val1 == 0:
print("This is not a Prime number, if val1 == 0")
answer = False
else:
print("This is a prime number, else val1 == 0")
answer = True
return answer
Also add a counter for testing to limit the recursion.
def prime(n, limit):
else:
limit += 1
if limit < 10:
val1 = n // prime(n - 1, limit)
Also, you should use either True/False or 0/1 for "answer" and not some combination.
def prime(n):
print "-"*30
print "starting prime with n =", n
if n == 0:
print("Equals zero, This is not a Prime number")
## zero = False
answer = 0
if n == 1:
print("Equals one, This is not a Prime number")
## one = True but you print that it is not prime
answer = 1
if val1 == 0:
print("This is not a Prime number, if val1 == 0")
## use of False, not zero
answer = False
else:
print("This is a prime number, else val1 == 0")
## use of True, not one
answer = True
I'm not sure about the question is, but try this code and see if it clarifies things.
name = 'Jack'
print '"name" is this memory address', id(name)
def say_hello():
print ('Hello ' + name + '!')
def change_name(new_name):
name = new_name
print "name is now", name
print '"name" is this memory address', id(name)
say_hello()
change_name("Joe")
print "after change name =", name
print '"name" is this memory address', id(name)
You can code the not found numbers in two ways:
message_tup = ("vodafone ", "o2 ", "meteor ")
found = False
for x in range(3):
if networkList[x] in prefix_list: ## x = 0 through 2
msg+= "\n %s\t" % (message_tup[x])
found = True
if not found:
print "none of these were found",
for x in range(3):
print prefix_list[x],
print
#
# or use a function
def find_prefix(networkList, prefix_list):
message_tup = ("vodafone ", "o2 ", "meteor ")
for x in range(3):
if networkList[x] in prefix_list:
msg+= "\n %s\t" % (message_tup[x])
return True
print "none of these were found",
for x in range(3):
print prefix_list[x],
print
return False
First, add some print statements for testing:
# add a colomn of 0
>>>for j in range(len(my_list)):
row = my_list[j]
row.append(0)
print "row now =", j, row
# Add a row of 0
>>>for i in range(len(my_list)):
colomn=my_list[i]
colomn.append(0)
print "column now =", i, colomn
#
# a matrix (list of lists) is usually created by two for loops
matrix = []
for x in range(size):
matrix.append([]) ## this row = empty list
for y in range(size): ## columns
matrix[x].append(0)
matrix[1][2] = 1 ## change one entry
print matrix
If you store the prefixes in a list:
prefix1=userInput1[:3]
prefix2=userInput2[:3]
prefix3=userInput3[:3]
##
## becomes
prefix_list = [prefix[:3] for prefix in userInput]
You can then clean up the if() statements:
if prefix1==networkList[0] or prefix2==networkList[0] or prefix3==networkList[0]:
msg+= "\n"+" vodafone ""\t"
#
# + the other if() statements becomes
message_tup = ("vodafone ", "o2 ", "meteor ")
for x in range(3):
if networkList[x] in prefix_list: ## x = 0 through 2
msg+= "\n %s\t" % (message_tup[x]) ## literal in tuple = same 0 through 2
This is the preferred way to do it as you can then easily modify the code with additions to the list instead of more if statements.
It would be something along these lines, see "Functions" here:
def CoM_positions(value_in):
if some_condition: ## or whatever
CoM_return = CoM(value_in)
print CoM_return, value_in
return CoM_return
return_value = find_positions(positions)
better_values= CoM_positions(return_value)
print better_values
It is also available with documentation here. Just copy it to /python/site-packages. I also changed the name of the file to graphicsZ.py because I didn't know it there would be name collusion with the wx graphics.py file.
There are two problems that I can see. It should be "root.mainloop" and there is no config statement for load menu so only the empty "menubar" is displayed. Also, note the inconsistent use of master and self.master. I did not test with any of the commented lines included. If they contain other problems that you can not solve, post back.
from Tkinter import *
class Application(Frame):
def __init__(self, master=None):
# Frame.__init__(self, master)
# self.master.rowconfigure(0, weight=1)
# self.master.columnconfigure(0, weight=1)
# self.master.title('Test Menu')
self.createMenu(master)
#self.createShell()
def createMenu(self, master):
# menubar = Menu(master)
loadmenu = Menu(master)
loadmenu.add_command(label='Load', command=self.load)
loadmenu.add_command(label='Save', command=self.save)
loadmenu.add_separator()
loadmenu.add_command(label='Quit', command=master.quit)
#master.grid()
master.config(menu=loadmenu)
def createShell(self):
frame = Frame(width=400, height=300)
frame.grid()
def load(self):
print "load called"
def save(self):
print "save called"
## this function is not being used by the code as it is now
def quit(self):
pass
root = Tk()
app = Application(master=root)
root.mainloop()
This is the last time I am explaining technique. Start out with something specific that works and expand to the general. Take this code which shows one specific set of 3, and then a second set, and expand so it will print one entire row, then expand so it will print all of the rows.
import graphics
def draw_circle(win, x, y, radius, colour):
centre = graphics.Point(x,y)
circle = graphics.Circle(centre, radius)
circle.setFill(colour)
circle.setWidth(2)
circle.draw(win)
width = 100
height = 100
win = graphics.GraphWin("Circles", width, height)
radius = width/20 ## 10 circles with radius = 1/2 diameter
x = radius ## up against the corner
y = radius
red = 0
for j in range(3):
color = "white"
if red == j:
color = "red"
draw_circle(win, x, y, radius, color)
## x moves radius X2
x += radius+radius
red += 1
x += radius*2
for j in range(3):
color = "white"
if red == j:
color = "red"
draw_circle(win, x, y, radius, color)
## x moves radius X2
x += radius+radius
raw_input("")