0% found this document useful (0 votes)
15 views

Tkinter Frame

Uploaded by

Tito Miguelin
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Tkinter Frame

Uploaded by

Tito Miguelin
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import tkinter as tk

from tkinter import ttk

def create_input_frame(container):

frame = ttk.Frame(container)

# grid layout for the input frame


frame.columnconfigure(0, weight=1)
frame.columnconfigure(0, weight=3)

# Find what
ttk.Label(frame, text='Find what:').grid(column=0, row=0, sticky=tk.W)
keyword = ttk.Entry(frame, width=30)
keyword.focus()
keyword.grid(column=1, row=0, sticky=tk.W)

# Replace with:
ttk.Label(frame, text='Replace with:').grid(column=0, row=1, sticky=tk.W)
replacement = ttk.Entry(frame, width=30)
replacement.grid(column=1, row=1, sticky=tk.W)

# Match Case checkbox


match_case = tk.StringVar()
match_case_check = ttk.Checkbutton(
frame,
text='Match case',
variable=match_case,
command=lambda: print(match_case.get()))
match_case_check.grid(column=0, row=2, sticky=tk.W)

# Wrap Around checkbox


wrap_around = tk.StringVar()
wrap_around_check = ttk.Checkbutton(
frame,
variable=wrap_around,
text='Wrap around',
command=lambda: print(wrap_around.get()))
wrap_around_check.grid(column=0, row=3, sticky=tk.W)

for widget in frame.winfo_children():


widget.grid(padx=0, pady=5)

return frame

def create_button_frame(container):
frame = ttk.Frame(container)

frame.columnconfigure(0, weight=1)

ttk.Button(frame, text='Find Next').grid(column=0, row=0)


ttk.Button(frame, text='Replace').grid(column=0, row=1)
ttk.Button(frame, text='Replace All').grid(column=0, row=2)
ttk.Button(frame, text='Cancel').grid(column=0, row=3)

for widget in frame.winfo_children():


widget.grid(padx=0, pady=3)
return frame

def create_main_window():

# root window
root = tk.Tk()
root.title('Replace')
root.geometry('400x150')
root.resizable(0, 0)
# windows only (remove the minimize/maximize button)
root.attributes('-toolwindow', True)

# layout on the root window


root.columnconfigure(0, weight=4)
root.columnconfigure(1, weight=1)

input_frame = create_input_frame(root)
input_frame.grid(column=0, row=0)

button_frame = create_button_frame(root)
button_frame.grid(column=1, row=0)

root.mainloop()

if __name__ == "__main__":
create_main_window()

You might also like