@@ -16,9 +16,14 @@ def __init__(self):
1616 self .root = tk .Tk ()
1717 self .root .title ("Cat Tinder" )
1818 self .root .geometry ("400x500" )
19- self .root .configure (background = 'grey' )
19+ self .root .minsize (400 , 500 )
20+ self .root .maxsize (400 , 500 )
21+ self .root .configure (background = 'black' )
2022 self .root .protocol ("WM_DELETE_WINDOW" , self .on_closing )
2123 #self.root.bind('<Motion>', self.motion)
24+ self .screen_x = self .root .winfo_screenwidth ()
25+ self .screen_y = self .root .winfo_screenheight ()
26+ self .jumpscare = False
2227 self .loop = asyncio .get_event_loop ()
2328 self .session = None
2429 self .images = list ()
@@ -34,12 +39,12 @@ async def get_cache(self):
3439 t = time .time ()
3540 if not self .session :
3641 self .session = aiohttp .ClientSession ()
37- for _ in range (10 ):
42+ for i in range (10 ):
3843 cat_data = dict ()
39- if randint (0 , 9 ) == 9 :
44+ if randint (1 , 10 ) == 5 and i :
4045 image_number = randint (1 ,10 )
4146 im = Image .open (os .path .join (self .dir , os .path .join ("res" , os .path .join ("images" , f"{ image_number } .jpg" ))))
42- im = im .resize ((400 , 400 ), Image .NEAREST )
47+ im = im .resize ((self . screen_x , self . screen_y - 150 ), Image .NEAREST )
4348 image = ImageTk .PhotoImage (im )
4449 cat_data .update ({"image" : image })
4550 cat_data .update ({"jumpscare" : True })
@@ -51,7 +56,7 @@ async def get_cache(self):
5156 async with self .session .get (url ) as res :
5257 image_bytes = await res .read ()
5358 im = Image .open (io .BytesIO (image_bytes ))
54- im = im .resize ((400 , 450 ), Image .NEAREST )
59+ im = im .resize ((400 , 440 ), Image .NEAREST )
5560 image = ImageTk .PhotoImage (im )
5661 cat_data .update ({"image" :image })
5762 async with self .session .get ("https://www.pawclub.com.au/assets/js/namesTemp.json" ) as res :
@@ -85,6 +90,9 @@ def all_children(self):
8590
8691
8792 def new_image (self , cat = None ):
93+ if self .jumpscare :
94+ self .root .maxsize (400 , 500 )
95+ self .jumpscare = False
8896 widget_list = self .all_children ()
8997 for item in widget_list :
9098 item .pack_forget ()
@@ -111,6 +119,9 @@ def new_image(self, cat= None):
111119 name .pack (side = tk .TOP )
112120 tk .Label (self .frame , image = image ).pack (side = tk .TOP )
113121 if jumpscare :
122+ self .jumpscare = True
123+ self .root .maxsize (self .screen_x , self .screen_y )
124+ self .root .geometry (f"{ self .screen_x } x{ self .screen_y } +0+0" )
114125 mixer .music .load (os .path .join (self .dir , os .path .join ("res" , os .path .join ("sounds" , "jumpscare.mp3" ))))
115126 mixer .music .play ()
116127 tk .Button (self .frame , text = "Like" , background = "green" , command = self .new_image ).pack (side = tk .BOTTOM )
@@ -123,7 +134,7 @@ def get_bio():
123134 widget_list = self .all_children ()
124135 for item in widget_list :
125136 item .pack_forget ()
126- self .frame = tk .Frame (self .root , bg = "black" )
137+ self .frame = tk .Frame (self .root , bg = "black" , height = 450 , width = 400 )
127138 bio = tk .Text (self .frame )
128139 bio .insert (tk .END , f"Name: { cat_name } \n " )
129140 bio .insert (tk .END , f"Age: { age } \n " )
@@ -132,17 +143,20 @@ def get_bio():
132143 bio .insert (tk .END , f"{ hobbies } \n " )
133144 bio .configure (state = "disabled" )
134145 bio .pack (side = tk .TOP )
135- tk .Button (self .frame , text = "Back To Photo" , background = "blue" , command = back_to_photo ).pack (side = tk .BOTTOM )
146+ tk .Button (self .frame , text = "Like" , background = "green" , command = self .new_image ).pack (side = tk .RIGHT )
147+ tk .Button (self .frame , text = "Dislike" , background = "red" , command = self .new_image ).pack (side = tk .LEFT )
148+ tk .Button (self .root , text = "Back To Photo" , background = "blue" , command = back_to_photo ).pack (side = tk .BOTTOM )
136149 self .frame .pack ()
137150 tk .Button (self .frame , text = "Bio" , background = "blue" , command = get_bio ).pack (side = tk .BOTTOM )
138151 self .frame .pack ()
139152 self .root .mainloop ()
140153
141154
142155 def on_closing (self ):
143- x = randint (0 , 1520 )
144- y = randint (0 , 580 )
145- self .root .geometry (f"+{ x } +{ y } " )
156+ if not self .jumpscare :
157+ max_x , max_y = self .screen_x - 400 , self .screen_y - 500
158+ x , y = randint (0 , max_x ), randint (0 , max_y )
159+ self .root .geometry (f"+{ x } +{ y } " )
146160
147161
148162 def motion (self ,event ):
0 commit comments