1
- from http . client import LineTooLong
1
+ import tkinter
2
2
import customtkinter as ctk
3
3
from tkinter import filedialog , Label , END
4
4
from CTkMessagebox import CTkMessagebox
@@ -154,12 +154,33 @@ def print_info_to_text_widget(self, log_box, info_type=''):
154
154
log_box .insert (END , line )
155
155
log_box .insert (END , '\n ' )
156
156
157
+ class ToplevelWindow (ctk .CTkToplevel ):
158
+ WIDTH = 480
159
+ HEIGHT = 580
160
+ def __init__ (self , * args , ** kwargs ):
161
+ super ().__init__ (* args , ** kwargs )
162
+ self .geometry (f"{ ToplevelWindow .WIDTH } x{ ToplevelWindow .HEIGHT } " )
163
+ self .text = tkinter .Text (self )
164
+ self .text .grid (padx = 5 , pady = 5 , sticky = "nswe" )
165
+ self .center_window (self )
166
+
167
+ def center_window (self , window ):
168
+ """Centers the window on the screen."""
169
+ sw = self .winfo_screenwidth ()
170
+ sh = self .winfo_screenheight ()
171
+
172
+ x = (sw - ToplevelWindow .WIDTH ) / 2
173
+ y = (sh - ToplevelWindow .HEIGHT ) / 2
174
+ self .geometry ("%dx%d+%d+%d" % (ToplevelWindow .WIDTH , ToplevelWindow .HEIGHT , x , y ))
175
+ window .focus_force ()
176
+ window .wm_attributes ("-topmost" , True )
177
+
157
178
class App (ctk .CTk ):
158
179
WIDTH = 960
159
180
HEIGHT = 590
160
181
DEBUG_ME = False
161
- def __init__ (self ):
162
- super ().__init__ ()
182
+ def __init__ (self , * args , ** kwargs ):
183
+ super ().__init__ (* args , ** kwargs )
163
184
self .folder_count = 0
164
185
self .file_count = 0
165
186
self .recursive_count = 1
@@ -168,6 +189,7 @@ def __init__(self):
168
189
self .title ("Recursive Symlink Creator" )
169
190
self .geometry (f"{ App .WIDTH } x{ App .HEIGHT } " ) # Increased height for log area
170
191
self .protocol ("WM_DELETE_WINDOW" , self .on_closing )
192
+ self .toplevel_window = None
171
193
172
194
# Configure root grid layout (3x1)
173
195
self .grid_columnconfigure (0 , weight = 1 )
@@ -271,6 +293,10 @@ def __init__(self):
271
293
self .create_clear_logbox_button = ctk .CTkButton (self .root_frame , text = "Clear Log Box" , width = 180 , command = self .clear_logbox )
272
294
self .create_clear_logbox_button .grid (row = 4 , column = 1 , pady = 5 , padx = 5 , sticky = "we" )
273
295
296
+ # Clear log box function
297
+ self .create_clear_logbox_button = ctk .CTkButton (self .root_frame , text = "New window" , width = 180 , command = self .open_toplevel )
298
+ self .create_clear_logbox_button .grid (row = 5 , column = 1 , pady = 5 , padx = 5 , sticky = "we" )
299
+
274
300
# Configure root_frame grid layout (2x2)
275
301
self .root_frame .grid_columnconfigure (2 , weight = 1 )
276
302
self .root_frame .grid_rowconfigure (1 , weight = 1 )
@@ -291,7 +317,13 @@ def center_window(self, window):
291
317
y = (sh - App .HEIGHT ) / 2
292
318
self .geometry ("%dx%d+%d+%d" % (App .WIDTH , App .HEIGHT , x , y ))
293
319
window .focus_force ()
294
- window .wm_attributes ("-topmost" , True )
320
+ # window.wm_attributes("-topmost", True)
321
+
322
+ def open_toplevel (self ):
323
+ if self .toplevel_window is None or not self .toplevel_window .winfo_exists ():
324
+ self .toplevel_window = ToplevelWindow (self ) # create window if its None or destroyed
325
+ else :
326
+ self .toplevel_window .focus () # if window exists focus it
295
327
296
328
def push_checkbox (self ):
297
329
if self .operate_folder_var .get ():
0 commit comments