|
Post by AnyKey on Apr 7, 2005 19:06:59 GMT -5
Okay, here's some code I had laying around. I don't really have any use for it, but I'm hoping somebody here will. [t] == Tab
#this code creates a searchable text widget from Tkinter import * root = Tk() root.title("Find by Eric Wood")
def find(): [t]t.tag_remove('found', '1.0', END) [t]thing = e.get() [t]pos = '1.0' [t]while 1: [t][t]pos = t.search(thing, pos, stopindex=END) [t][t]if not pos: [t][t]break [t][t]pos2 = '%s+%dc' % (pos, len(thing)) [t][t]t.tag_add("found", pos, pos2) [t][t]pos = pos2 [t]t.tag_config("found", background = "red")
fram = Frame(root) e = Entry(fram, width = 20) e.pack(side = LEFT, fill = BOTH, expand = 1) b= Button(fram, text = "Find", command = find) b.pack(side = RIGHT) fram.pack(side = TOP)
t = Text(root) t.insert(END, "Testing...1...2...3...") t.pack(side = BOTTOM) root.mainloop()
Too be continued...
|
|
|
Post by AnyKey on Apr 7, 2005 19:08:46 GMT -5
#creates a window that dissapears for given time from Tkinter import *
root = Tk() app = Frame(root) app.grid()
def show(): [t]root.deiconify() [t]root.title("It's Me Again!")
def hide(): [t]root.withdraw() [t]time = e.get() [t]time = int(time) [t]time *= 1000 [t]print time [t]root.after(time, show)
e = Entry(app) e.grid(row=0, column=0)
b = Button(app, text = "Hide", command = hide) b.grid(row=0, column=1)
root.title("Hide Me!") root.mainloop()
|
|
|
Post by AnyKey on Apr 7, 2005 19:14:07 GMT -5
I can't remember whether or not this works, but I gave up on it a long time ago.
#Life: an ecosystem simulator in which 'animals' move around & interact #moves an 'animal' around canvas #by Eric Wood #7-26-04
from Tkinter import * import random class Application(Frame): [t]def __init__(self, master): [t][t]Frame.__init__(self, master) [t][t]self.grid() [t][t]self.create_widgets()
[t]def create_widgets(self): [t][t]self.movenum = StringVar(self) [t][t]self.num = 0 [t][t]self.lbl = Label(self, textvariable = self.movenum) [t][t]self.lbl.grid() [t][t]self.movenum.set("Moves: 0")
[t][t]self.c = Canvas(self, height = 200, width = 200) [t][t]self.c.grid() [t][t]self.c.create_rectangle(2, 2, 201, 201, fill = "#00FF00") [t][t] [t][t]self.b = Button(self, text = "Move", command = self.move) [t][t]self.b.grid()
[t][t]self.animals = [] [t][t]self.prey = []
[t][t]for i in range(10): [t][t][t]x = random.randrange(189) [t][t][t]y = random.randrange(189) [t][t][t]self.animal = self.c.create_text(x, y, text = "O") [t][t][t]num = [self.animal, x, y, 0] [t][t][t]self.animals.append(num)
[t][t]for i in range(10): [t][t][t]x = random.randrange(189) [t][t][t]y = random.randrange(189) [t][t][t]prey = self.c.create_text(x, y, text = "o") [t][t][t]num = [prey, x, y, 0] [t][t][t]self.prey.append(num)
[t]def move(self): [t][t]self.num += 1 [t][t]for i in self.animals: [t][t][t]self.movenum.set("Moves: " + str(self.num)) [t][t][t]num = random.randrange(4)
[t][t][t]if num == 0: [t][t][t][t]i[1] += 10 [t][t][t][t]if i[1] > 90: [t][t][t][t][t]i[1] -= 10 [t][t][t][t]if i[1] < 10: [t][t][t][t][t]i[1] += 10 [t][t][t][t][t] [t][t][t]elif num == 1: [t][t][t][t]i[1] -= 10 [t][t][t][t]if i[1] > 190: [t][t][t][t][t]i[1] -= 10 [t][t][t][t]if i[1] < 10: [t][t][t][t][t]i[1] += 10
[t][t][t]elif num == 2: [t][t][t][t]i[2] -= 10 [t][t][t][t]if i[2] > 190: [t][t][t][t][t]i[2] -= 10 [t][t][t][t]if i[2] < 10: [t][t][t][t][t]i[2] += 10
[t][t][t]elif num == 3: [t][t][t][t]i[2] += 10 [t][t][t][t]if i[2] > 190: [t][t][t][t][t]i[2] -= 10 [t][t][t][t]if i[2] < 10: [t][t][t][t][t]i[2] += 10
[t][t][t]self.c.coords(i[0], i[1], i[2]) [t][t][t]i[3] += 1
[t][t][t]if i[3] > 10: [t][t][t][t]self.c.delete(i[0]) [t][t][t][t]del i
[t][t][t]self.move_prey()
[t]def move_prey(self):
[t][t]for i in self.prey: [t][t][t]num = random.randrange(4)
[t][t][t]if num == 0: [t][t][t][t]i[1] += 10 [t][t][t][t]if i[1] > 90: [t][t][t][t][t]i[1] -= 10 [t][t][t][t]if i[1] < 10: [t][t][t][t][t]i[1] += 10 [t][t][t][t][t] [t][t][t]elif num == 1: [t][t][t][t]i[1] -= 10 [t][t][t][t]if i[1] > 190: [t][t][t][t][t]i[1] -= 10 [t][t][t][t]if i[1] < 10: [t][t][t][t][t]i[1] += 10
[t][t][t]elif num == 2: [t][t][t][t]i[2] -= 10 [t][t][t][t]if i[2] > 190: [t][t][t][t][t]i[2] -= 10 [t][t][t][t]if i[2] < 10: [t][t][t][t][t]i[2] += 10
[t][t][t]elif num == 3: [t][t][t][t]i[2] += 10 [t][t][t][t]if i[2] > 190: [t][t][t][t][t]i[2] -= 10 [t][t][t][t]if i[2] < 10: [t][t][t][t][t]i[2] += 10
[t][t][t]self.c.coords(i[0], i[1], i[2]) [t][t][t]i[3] += 1 [t][t][t]self.i = i
[t][t][t]for y in self.animals: [t][t][t][t]if self.i[1]-10 == y[1] or self.i[1]+10 == y[1] or self.i[2]-10 == y[2] or self.i[2]+10 == y[2]: [t][t][t][t][t]self.c.delete(self.i[0]) [t][t][t][t][t]self.prey.remove(self.i) [t][t][t][t][t]y[3] = 0
[t][t][t] [t]def reproduce(self, i): [t][t]self.animal = self.c.create_text(i[1] - 10, i[2], text = "@") [t][t]num = [self.animal, i[1] - 10, i[2], 0] [t][t]self.animals.append(num)
root = Tk() root.resizable(0,0) root.title("Life - A Habitat Sim") app = Application(root) root.mainloop()
|
|
|
Post by AnyKey on Apr 7, 2005 19:16:23 GMT -5
That's all I have for now. If I get the time I'll post some CalcStat code ;D
|
|
|
Post by bfr on Apr 7, 2005 20:28:34 GMT -5
Awesome!
|
|
|
Post by Pure on Apr 8, 2005 18:31:12 GMT -5
that looks nice!
|
|
|
Post by AnyKey on Apr 12, 2005 18:57:01 GMT -5
Somebody should move this to the main source section.
|
|
|
Post by Pure on Apr 12, 2005 21:37:34 GMT -5
now in the main source section!
|
|
|
Post by Vladik on Apr 16, 2005 18:39:24 GMT -5
Nice!
|
|
|
Post by Pure on Apr 16, 2005 21:21:49 GMT -5
BACK On TOPIC PLEASE!
|
|
|
Post by AnyKey on Apr 20, 2005 17:59:37 GMT -5
Huh? That is the topic. People come and marvel at my 1337 pr0gr4mm1ng skillz! ;D
|
|
|
Post by bfr on Apr 20, 2005 18:24:37 GMT -5
Lol... btw your website has an ad in the backround
|
|
|
Post by Pure on Apr 20, 2005 19:50:21 GMT -5
|
|
|
Post by bfr on Apr 20, 2005 20:47:39 GMT -5
|
|
|
Post by Pure on Apr 21, 2005 19:49:14 GMT -5
I was angry at that time... btw, three minutes ago, Simon was logged in!
|
|
|
Post by bfr on Apr 22, 2005 16:45:31 GMT -5
So you were serious?
We better get back on topic.....
|
|
|
Post by Pure on Apr 22, 2005 17:13:04 GMT -5
we are officially back on topic as of....
...Some Python Code...
NOW!!
|
|
|
Post by AnyKey on May 15, 2005 21:57:04 GMT -5
I have some more laying around. I don't have time to submit it now, though. Coming soon!
|
|
|
Post by Pure on May 18, 2005 14:07:04 GMT -5
when?
|
|
|
Post by AnyKey on May 18, 2005 17:14:03 GMT -5
When I say so.
|
|