-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
596 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import tkinter as tk | ||
|
||
root = tk.Tk() | ||
l = tk.Label(root, text='starting...', font='Arial 36') | ||
l.pack() | ||
label = tk.Label(root, text='starting...', font='Arial 36') | ||
label.pack() | ||
|
||
l.bind('<Enter>', lambda e: l.configure(text='mouse inside')) | ||
l.bind('<Leave>', lambda e: l.configure(text='mouse outside')) | ||
l.bind('<1>', lambda e: l.configure(text='mouse click')) | ||
|
||
root.mainloop() | ||
label.bind('<Enter>', lambda e: l.configure(text='mouse inside')) | ||
label.bind('<Leave>', lambda e: l.configure(text='mouse outside')) | ||
label.bind('<1>', lambda e: l.configure(text='mouse click')) | ||
|
||
root.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# draw straight lines on a canvas | ||
from tklib import * | ||
|
||
class Canvas(tk.Canvas): | ||
"""Define a canvas with line drawing""" | ||
|
||
def __init__(self, **kwargs): | ||
# super(Canvas, self).__init__(App.stack[-1], width=w, height=h, bg='light blue') | ||
super(Canvas, self).__init__(App.stack[-1], **kwargs) | ||
self.grid() | ||
self.bind('<Button-1>', self.start) | ||
self.bind('<B1-Motion>', self.move) | ||
self.bind('<D>', self.print_msg) | ||
self.bind('<Key>', self.print_msg) | ||
self.bind('<Return>', self.print_msg) | ||
|
||
|
||
def start(self, event=None): | ||
# Execute a callback function. | ||
self.x0 = event.x | ||
self.y0 = event.y | ||
self.id = self.create_line(self.x0, self.y0, self.x0, self.y0) | ||
self.itemconfig(self.id, fill=color.var.get()) | ||
self.itemconfig(self.id, width=thickness.var.get()) | ||
|
||
def move(self, event=None): | ||
self.x1 = event.x | ||
self.y1 = event.y | ||
self.coords(self.id, self.x0, self.y0, self.x1, self.y1) | ||
|
||
def print_msg(self, event): | ||
print(event) | ||
|
||
app = App('Drawing lines on a canvas') | ||
color = Combobox('Color', 'black;red;green;blue;yellow;cyan;magenta') | ||
thickness = Combobox('Thickness', '1;2;5;10;20') | ||
Canvas(width=600, height=200) | ||
|
||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# draw straight lines on a canvas | ||
from tklib import * | ||
|
||
class Canvas(tk.Canvas): | ||
"""Define a canvas with line drawing""" | ||
|
||
def __init__(self, **kwargs): | ||
# super(Canvas, self).__init__(App.stack[-1], width=w, height=h, bg='light blue') | ||
super(Canvas, self).__init__(App.stack[-1], **kwargs) | ||
self.grid() | ||
self.bind('<Button-1>', self.start) | ||
self.bind('<B1-Motion>', self.move) | ||
self.bind('<D>', self.print_msg) | ||
self.bind('<Key>', self.print_msg) | ||
self.bind('<Return>', self.print_msg) | ||
|
||
|
||
def start(self, event=None): | ||
# Execute a callback function. | ||
self.x0 = event.x | ||
self.y0 = event.y | ||
self.id = self.create_line(self.x0, self.y0, self.x0, self.y0) | ||
self.itemconfig(self.id, fill=color.var.get()) | ||
self.itemconfig(self.id, width=thickness.var.get()) | ||
|
||
def move(self, event=None): | ||
self.x1 = event.x | ||
self.y1 = event.y | ||
self.coords(self.id, self.x0, self.y0, self.x1, self.y1) | ||
|
||
def print_msg(self, event): | ||
print(event) | ||
|
||
colors = ('red', 'blue', 'green', 'cyan', 'magenta', 'yellow', 'black') | ||
|
||
app = App('Drawing lines on a canvas') | ||
color = Combobox('Color', 'black;red;green;blue;yellow;cyan;magenta') | ||
thickness = Combobox('Thickness', '1;2;5;10;20') | ||
|
||
canvas = Canvas(width=600, height=200) | ||
|
||
x = 10 | ||
d = 20 | ||
for col in colors: | ||
id = canvas.create_rectangle(x, 0, x+d, d, fill=col) | ||
canvas.tag_bind(id, '<Button-1>', lambda e : print(eval(col))) | ||
|
||
x += d | ||
|
||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.