Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5217669

Browse files
code updated
1 parent a986b5e commit 5217669

File tree

1 file changed

+67
-22
lines changed

1 file changed

+67
-22
lines changed

‎sticky notes/main.py

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,70 @@
11
# sticky notes application
2-
import tkinter as tk
3-
4-
def display():
5-
import time
6-
current_time = time.strftime("%H:%M")
7-
print("Welcome to Sticky notes. Here you can create sticky notes, easily.")
8-
time.sleep(2)
9-
note_input = input("Type your notes ")
10-
note = ("%s") % note_input
11-
time.sleep(1)
12-
# prevents GUI from popping up before it receives input.
13-
root = tk.Tk()
14-
root.title("Sticky notes")
15-
root.geometry("400x400")
16-
# changes size of the GUI.
17-
tk.Label(root, text=current_time).pack()
18-
tk.Label(root, text=note).pack()
19-
# prints the inputed text by user.
20-
root.mainloop()
21-
# keeps the sticky notes open and display text until the program is closed.
22-
23-
display()
2+
import tkinter
3+
from tkinter import Toplevel,Frame,X,TOP,Label,RIGHT,LEFT,BOTH,Tk
4+
import tkinter.scrolledtext as tkst
5+
from tkinter import messagebox
6+
from tkinter import font
247

8+
no_of_windows = 1
259

10+
11+
class StickyNotes(Toplevel):
12+
def __init__(self, master, **kwargs):
13+
super().__init__(master, **kwargs)
14+
self.xclick = 0
15+
self.yclick = 0
16+
17+
# master (root) window
18+
self.overrideredirect(True)
19+
global no_of_windows
20+
self.geometry('350x450+' + str(1000+no_of_windows*(-30)) + '+' + str(100 + no_of_windows*20))
21+
self.config(bg = '#838383')
22+
self.attributes('-topmost', 'true')
23+
self.resizable(True,True)
24+
25+
# titlebar
26+
self.titlebar = Frame(self , bg = '#F8F796', relief = 'flat', bd = 2)
27+
self.titlebar.bind('<Button-1>', self.get_pos)
28+
self.titlebar.bind('<B1-Motion>', self.move_window)
29+
self.titlebar.pack(fill = X, expand = 1, side = TOP)
30+
31+
self.closebutton = Label(self.titlebar, text = 'X', bg = '#F8F7B6', relief = 'flat')
32+
self.closebutton.bind('<Button-1>', self.quit_window)
33+
self.closebutton.pack(side = RIGHT)
34+
35+
self.newbutton = Label(self.titlebar, text = '+', bg = '#F8F7B6', relief = 'flat')
36+
self.newbutton.pack(side = LEFT)
37+
self.newbutton.bind('<Button-1>', self.another_window)
38+
39+
self.mainarea = tkst.ScrolledText(self, bg = '#FDFDCA', font=('Comic Sans MS', 14, 'italic'), relief = 'flat', padx = 5, pady = 10)
40+
self.mainarea.pack(fill = BOTH, expand = 1)
41+
42+
43+
no_of_windows += 1
44+
45+
def get_pos(self, event):
46+
self.xclick = event.x
47+
self.yclick = event.y
48+
49+
def move_window(self, event):
50+
self.geometry('+{0}+{1}'.format(event.x_root-self.xclick, event.y_root-self.yclick))
51+
52+
def another_window(self, event):
53+
StickyNotes(root)
54+
55+
def quit_window(self, event):
56+
self.closebutton.config(relief = 'flat', bd = 0)
57+
if(messagebox.askyesno('Delete Note?','Are you sure you want to delete this note?', parent = self)):
58+
global no_of_windows
59+
self.destroy()
60+
no_of_windows -= 1
61+
if(no_of_windows == 1):
62+
root.destroy()
63+
return
64+
self.closebutton.config(relief = 'flat', bd = 0, bg = '#F8F7B6')
65+
66+
root = Tk()
67+
root.withdraw()
68+
#first note start.
69+
sticky = StickyNotes(root)
70+
root.mainloop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /