-
Notifications
You must be signed in to change notification settings - Fork 0
/
homework_to_wallpaper.py
202 lines (134 loc) · 5.71 KB
/
homework_to_wallpaper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
from cgitb import enable
from glob import escape
from turtle import width
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
#import tkinter as tk
from tkinter import *
import os
import time
import ctypes
list_of_work = {}
user_name = os.getlogin()
#tk setup
root = Tk()
root.title("Homework on Wallpaper!")
def myClick():
myClick = Label(root, text ="Enter you wallpaper save location")
myClick.grid(row=3)
myLabel1 = Label(root, text="WARNING: THIS PROGRAM WILL CHANGE YOUR WALLPAPER INSTANTLY AFTER IT'S FINISHED. PLS REMEMBER TO RECORD THE OLD WALLPAPER FILE LOCATION")
myLabel2 = Label(root, text="Copyright to Leo Yu")
save_location = Entry(root, width=50)
subject1 = Label(root, text = 'Subject #1')
detail1 = Entry(root, width=100)
myLabel1.grid(row=0, columnspan=3)
myLabel2.grid(row=1, columnspan=3)
myClick()
save_location.grid(row=4) #griding the textinput
subject1.grid(row=5) #griding the first subject
detail1.grid(row=6) #griding the first detail of the subject
root.mainloop()
#script_dir = os.path.dirname(file_loc) #<-- absolute dir the script is in
#rel_path = "/works.png"
#abs_file_path = os.path.join(script_dir, rel_path)
#Copyright to https://www.codegrepper.com/code-examples/python/text+to+image+python
print("WARNING: THIS PROGRAM WILL CHANGE YOUR WALLPAPER INSTANTLY AFTER IT'S FINISHED. PLS REMEMBER TO RECORD THE OLD WALLPAPER FILE LOCATION")
def text_to_image(text):
def getSize(txt, font):
testImg = Image.new('RGB', (1, 1))
testDraw = ImageDraw.Draw(testImg)
return testDraw.textsize(txt, font)
if __name__ == '__main__':
fontname = "arial.ttf"
fontsize = 30
colorText = "black"
colorOutline = "white"
colorBackground = "white"
font = ImageFont.truetype(fontname, fontsize)
width, height = getSize(text, font)
img = Image.new('RGB', (width+1920, height+1080), colorBackground)
d = ImageDraw.Draw(img)
d.text((750, height/2), text, fill=colorText, font=font)
d.rectangle((0, 0, width+1920, height+1080), outline=colorOutline)
img.save(file_loc)
#omg that part is finally done.
#code for funny person. I guess i will never put this into use
def personality():
personality = input('This is just a funny question: Are you a funny person? y/n')
if personality == 'y':
print('ok guess u r a funny person. YaY')
return 'y'
elif personality == 'yes':
print('...i told you to answer with y or n and you answered yes... I guess u r a funny person then! :)')
return 'y'
elif personality == 'n':
print('Sorry for that ridiculous quesion. Here is the code:')
return 'n'
elif personality == 'no':
print('...i told you to answer with y or n and you answered no... I guess u r a funny person then! :)')
return 'y'
#here is the code for NOT funny person
def ur_homework():
#subject_abbr = {'Social Studies' : 'sos', 'French' : 'fre', 'Technology' : 'tec', 'Science' : 'sci', 'Math' : 'mat', 'Christian Education' : 'ce', 'English' : 'eng'}
subject_q = str(input('Subject: '))
detail = str(input('Detail: '))
list_of_work[subject_q] = detail
more = str(input('Do u have more? y/n: '))
if more == 'y':
#print('k, gald to hear that! *evil laugh*')
#print(list_of_work)
ur_homework()
elif more == 'yes':
#print('...i told you to answer with y or n and you answered yes... I guess u have more stuff then! :)')
#print(list_of_work)
ur_homework()
elif more == 'n':
#print('Ok then, pls check ur wallpaper!')
#print('Please check your wallpaper.')
#print(list_of_work)
return list_of_work
elif more == 'no':
#print('...i told you to answer with y or n and you answered no... Too bad...')
#print('Please check your wallpaper.')
#print(list_of_work)
return list_of_work
def isChangingMore():
isChanging = input('Are you using this program to make changes?')
if isChanging == 'yes':
isAdding = input("Adding more details?")
if isAdding == 'yes':
isAddingMore()
else:
changeSub = input('Subject to change:')
changeDetail = input('New detail:')
# 上次写道这儿,接着要询问用户需要更改的subject细节
with open(txt_file_loc, 'w') as f:
else:
def isAddingMore():
quit
def dic_to_text(works):
with open(txt_file_loc, 'w') as f:
for title, detail in works.items():
f.write(f'{title.upper()}:\n{detail}\n\n')
with open(txt_file_loc, 'r') as f:
pass
#print(f.read())
#using defs
file_loc_folder = input(f'Homework image file storage location (Leave blank if want it by default location: C:\\Users\\{user_name}\\Desktop\\Homeworks): ')
if file_loc_folder == '':
file_loc_folder = r"C:\Users" + "\\" + user_name + "\\" + r"Desktop\Homeworks"
txt_file_loc = file_loc_folder + '\\homeworks.txt'
if not os.path.exists(file_loc_folder):
os.makedirs(file_loc_folder)
if __name__ == '__main__':
file_loc = file_loc_folder + '\\' + 'homeworks.png'
print(file_loc_folder)
ur_homework()
dic_to_text(list_of_work)
homeworks = open(txt_file_loc, 'r')
text_to_image(homeworks.read())
print("Please check your wallpaper!")
print("Press ctrl c to quit the program :)")
ctypes.windll.user32.SystemParametersInfoW(20, 0, file_loc , 0)
time.sleep(100000)