import tkinter as tk
# Main window generation
tk1 = tk.Tk()
# Specify window size
tk1.geometry("900x600")
# Specify window title
tk1.title("TextConv 2020")
# Window size changeability setting
tk1.resizable(0,0)
# Window background color
tk1.configure(bg="white")
tk1.mainloop()
tk1.withdraw () # Do not suppress window display
from tkinter import filedialog
def m_load():
typ = [('text file','* .txt')]
dir = 'C:\\'
file = filedialog.askopenfilename(filetypes = typ, initialdir = dir)
f = open(file)
fdata = f.read () # Returns all read data up to the end of the file
textField.delete('1.0', 'end')
textField.insert('1.0', fdata)
f.close()
def m_save():
file = filedialog.asksaveasfilename()
txt = textField.get('1.0', 'end -1c')
f=open(file, mode='w')
f.write(txt)
f.close()
# Create menu bar
men = tk.Menu(tk1)
# Set the menu bar on the screen
tk1.config(menu=men)
# Create a parent menu (file) in the menu
menu_file = tk.Menu(tk1)
men.add_cascade(label='File', menu=menu_file)
men.add_cascade(label='File Load', command=m_load)
men.add_cascade(label='File Save', command=m_save)
## orient: vertical or horizontal
## bg: Border color
pack
## expand: Variable (True or False)
## fill: Movement when space is available (tk.BOTH spreads vertically and horizontally)
## side: From which direction to pack when arranging (side or top ...)
pw_main = tk.PanedWindow(tk1, orient='horizontal')
pw_main.pack(expand=True, fill = tk.BOTH, side="left")
pw_left = tk.PanedWindow(pw_main, bg="cyan", orient='vertical')
pw_main.add(pw_left)
pw_right = tk.PanedWindow(pw_main, bg="white", orient='vertical')
pw_main.add(pw_right)
mainFrame = tk.Frame(pw_left, width=450, height=600, bg="white")
# If propagation is set to False, the frame size will be width, height.
# If True, stick to the widget inside
mainFrame.propagate(False)
mainFrame.pack()
def c_button1_click():
# Read from clipboard
MOji1 = tk1.clipboard_get()
#txt1.insert(0,"test")
The #insert () method specifies the position in the first argument and the character to insert in the second argument.
textField.delete('1.0', 'end')
textField.insert('1.0', MOji1)
# textField.insert ('1.0',' Aiueo \ n Aiu Aiu \ nabcABCabcABC \ n123123')
def c_button2_click():
# Read from clipboard
textField.clipboard_append
# Button (pasted from clipboard)
c_button1 = tk.Button (clipboardFrame, text ='Paste from clipboard', command = c_button1_click, bg = "yellow")
c_button1.place(x=10, y=5)
# Button (copy to clipboard)
c_button2 = tk.Button (clipboardFrame, text = "copy to clipboard", command = c_button2_click, bg = "gold")
c_button2.place(x=150, y=5)
# scroll bar
scrollbar = tk.Scrollbar(textFrame)
scrollbar.pack(side=tk.RIGHT, fill="y")
# Text box
textField = tk.Text(textFrame, width=500, height=500, bd=5, relief="groove")
textField.propagate(False)
textField.pack(side=tk.LEFT, padx=(0, 0), pady=(0, 0))
textField["yscrollcommand"] = scrollbar.set
textField.insert ('1.0',' Aiueo \ nAiu \ nabcABCabcABC \ n123123')
padx: Lateral gap on the outside = 10 Both sides = (10,10) Left, right pady: outer vertical gap Because it shows the correlation position with the front and left ones, not the absolute coordinates When using (,), it is easier to set (n, 0) and 0 after it. The default is Tk.CENTER. In addition, Tk.W (left side), Tk.E (right side), Tk.N (top side), Tk.S (bottom side), Tk.NW (upper left), Tk.SW (lower left), Tk.NE (upper right), Tk.SE (lower right)
chk1 = tk.Checkbutton (SideFrame1, text ='line', bg = "lightgreen")
chk1.place(x=180, y=7)
S_button1 = tk.Button (SideFrame2, text = "replacement", command = lambda: c_button_click (10), bg = "salmon")
import tkinter.ttk as ttk
note = ttk.Notebook(tk1)
tab = tk.Frame(note,height=100,width=100)
note.add(tab, text="Tab")
note.pack()
Recommended Posts