Skip to content

Commit db41148

Browse files
committed
tkinter
1 parent b67f617 commit db41148

File tree

8 files changed

+127
-0
lines changed

8 files changed

+127
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
# http://stackoverflow.com/questions/33855618/how-to-configure-a-polygon-on-a-tkinter-canvas-in-python-using-a-class
4+
5+
try:
6+
import Tkinter as tk # python 2
7+
except:
8+
import tkinter as tk # python 3
9+
10+
11+
# --- class ---
12+
13+
class GUI(tk.Canvas):
14+
'''
15+
Inherits Canvas class (all Canvas methodes, attributes will be accessible)
16+
You can add your customized methods here.
17+
'''
18+
19+
def __init__(self,master,*args,**kwargs):
20+
tk.Canvas.__init__(self, master=master, *args, **kwargs)
21+
self.poly = None
22+
23+
def create_poly(self, points, outline='gray', fill='gray', width=2):
24+
self.poly = self.create_polygon(points, outline=outline, fill=fill, width=width)
25+
26+
def set_poly_fill(self, color):
27+
if self.poly:
28+
self.itemconfig(self.poly, fill=color)
29+
30+
# --- main ---
31+
32+
root = tk.Tk()
33+
34+
polygon = GUI(root)
35+
polygon.create_poly( [150,75,225,0,300,75,225,150] )
36+
polygon.set_poly_fill('red')
37+
polygon.pack()
38+
39+
root.mainloop()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python3
2+
3+
import tkinter as tk # Python 3
4+
5+
class App(tk.Tk):
6+
7+
def __init__(self):
8+
super().__init__()
9+
10+
App().mainloop()
11+
12+
#app = App()
13+
#app.mainloop()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
import Tkinter as tk # Python 2
4+
5+
class App(tk.Tk):
6+
7+
def __init__(self):
8+
tk.Tk.__init__(self) # Python 2
9+
10+
self.title('Main Window')
11+
self.geometry('300x300')
12+
13+
# def run(self):
14+
# self.mainloop()
15+
16+
#app = App()
17+
#app.run()
18+
19+
#App().run()
20+
21+
App().mainloop()
22+
23+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
3+
import tkinter as tk # Python 3
4+
5+
class App(tk.Tk):
6+
7+
def __init__(self):
8+
#super(App, self).__init__() # Python 3
9+
super().__init__() # Python 3
10+
11+
self.title('Main Window')
12+
self.geometry('300x300')
13+
14+
# def run(self):
15+
# self.mainloop()
16+
17+
#app = App()
18+
#app.run()
19+
20+
#App().run()
21+
22+
App().mainloop()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
import Tkinter as tk # Python 2
4+
5+
tk.Tk().mainloop()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python3
2+
3+
import tkinter as tk # Python 3
4+
5+
tk.Tk().mainloop()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
3+
try:
4+
import Tkinter as tk # Python 2
5+
except:
6+
import tkinter as tk # Python 3
7+
8+
tk.Tk().mainloop()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
3+
try:
4+
import Tkinter as tk # Python 2
5+
except:
6+
import tkinter as tk # Python 3
7+
8+
root = tk.Tk()
9+
10+
# all functions put here
11+
12+
root.mainloop()

0 commit comments

Comments
 (0)