最後の画像の余白を除去したいです。
ある程度 元のデザインから簡素化しましたが 行列構成に 大きな違いはございません。
ご見解頂けますと幸いです
python
1import tkinter as tk 2import tkinter.ttk as ttk 3import math 4import os 5 6def resource_path(relative_path): 7 try: 8 base_path = sys._MEIPASS 9 except Exception: 10 base_path = os.path.abspath(".") 11 12 return os.path.join(base_path, relative_path) 13 14def adjust_windowsize1(root): 15 ww = root.winfo_screenwidth() 16 wh = root.winfo_screenheight() 17 18 lw = math.ceil(ww * 0.3208) 19 lh = math.ceil(wh * 0.477) 20 21 root.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2))) 22 23def adjust_windowsize2(root): 24 ww = root.winfo_screenwidth() 25 wh = root.winfo_screenheight() 26 27 lw = math.ceil(ww * 0.3208) 28 lh = math.ceil(wh * 0.097) 29 30 root.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2))) 31 32def generate_frame(root): 33 34 def generate_subwindow1(): 35 36 dlg_modal = tk.Toplevel() 37 38 dlg_modal.grab_set() 39 dlg_modal.focus_set() 40 dlg_modal.transient(root) 41 42 adjust_windowsize1(dlg_modal) 43 44 dlg_modal.grid_columnconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1) 45 dlg_modal.grid_rowconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1) 46 47 frmTable = ttk.Frame(dlg_modal, name="frmTable") 48 frmTable.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S) 49 frmTable.grid_columnconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1, minsize=40) 50 frmTable.grid_rowconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1) 51 52 tree4 = ttk.Treeview(frmTable, show="headings", height=15) 53 tree4.grid(row=0, column=0, columnspan=10, rowspan=10, sticky=tk.E + tk.W, pady=(10,0), padx=(10,10)) 54 55 ybar4 = ttk.Scrollbar(frmTable, orient=tk.VERTICAL, command=tree4.yview) 56 ybar4.grid(row=0, column=9, rowspan=10, sticky=tk.N + tk.S + tk.E, pady=(10,0), padx=(0,10)) 57 tree4.config(yscrollcommand=lambda f, l: ybar4.set(f, l)) 58 59 xbar4 = ttk.Scrollbar(frmTable, orient=tk.HORIZONTAL, command=tree4.xview) 60 xbar4.grid(row=10, column=0, columnspan=10, sticky=tk.N + tk.S + tk.E + tk.W, padx=(10,10)) 61 tree4.config(xscrollcommand=lambda f, l: xbar4.set(f, l)) 62 63 btn_ReturnConvMenu = ttk.Button(frmTable, text = "閉じる", command=dlg_modal.destroy) 64 btn_ReturnConvMenu.grid(row=11, column=9, sticky=tk.N + tk.S + tk.E + tk.W, padx=(0,10)) 65 66 67 def change_frame(frame): 68 frame.tkraise() 69 70 71 style = ttk.Style() 72 style.theme_use('winnative') 73 style.configure("TFrame", background="#FFFFCC") 74 style.configure("TLabel", font=("Arial", 16), anchor='', background="#FFFFCC") 75 style.configure("TLabelframe", background="#FFFFCC", relief="sunken") 76 style.configure("TLabelframe.Label", foreground="red", font=("Arial", 16), background="#FFFFCC") 77 78 frm1 = ttk.Frame(root, name="frm1") 79 frm1.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S) 80 81 btn_SettingMenu = ttk.Button(frm1, text = "入出力", command=lambda: change_frame(frm2)) 82 btn_SettingMenu.pack(fill = tk.BOTH, expand=True) 83 btn_SettingMenu.bind('<Return>', lambda a: change_frame(frm2)) 84 85 btn_SettingMenu = ttk.Button(frm1, text = "変換", command=lambda: change_frame(frm3)) 86 btn_SettingMenu.pack(fill = tk.BOTH, expand=True) 87 btn_SettingMenu.bind('<Return>', lambda a: change_frame(frm3)) 88 89 btn_RunMenu = ttk.Button(frm1, text = "") 90 btn_RunMenu.pack(fill = tk.BOTH, expand=True) 91 btn_RunMenu.focus_set() 92 93 btn_Close = ttk.Button(frm1, text = "終了", command=root.destroy) 94 btn_Close.pack(fill = tk.BOTH, expand=True) 95 96 # 97 frm2 = ttk.Frame(root, name="frm2") 98 frm2.grid_rowconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1) 99 frm2.grid_columnconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1, minsize=40) 100 frm2.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S) 101 102 ent_RecName = ttk.Entry(frm2, font=("Arial", 16)) 103 ent_RecName.grid(row=0, column=2, columnspan=8, sticky=tk.E + tk.W + tk.N + tk.S, pady=(10,0), padx=(0,10)) 104 105 btn_AssignInputFile = ttk.Button(frm2, text = "入力") 106 btn_AssignInputFile.grid(row=1, column=0, columnspan=2, sticky=tk.E + tk.W + tk.N + tk.S, padx=(10,0)) 107 108 ent_InputPath = ttk.Entry(frm2, state="disabled", font=("Arial", 16)) 109 ent_InputPath.grid(row=1, column=2, columnspan=8, sticky=tk.E + tk.W + tk.N + tk.S, padx=(0,10)) 110 111 ent_OutputPath = ttk.Entry(frm2, state="disabled", font=("Arial", 16)) 112 ent_OutputPath.grid(row=2, column=2, columnspan=8, sticky=tk.E + tk.W + tk.N + tk.S, padx=(0,10)) 113 114 tree1 = ttk.Treeview(frm2, show="tree") 115 tree1.grid(row=3, column=0, rowspan=4, columnspan=4, sticky=tk.E + tk.W + tk.N + tk.S, pady=(10,0), padx=(10,0)) 116 117 ybar1 = ttk.Scrollbar(frm2, orient=tk.VERTICAL, command=tree1.yview) 118 ybar1.grid(row=3, column=3, rowspan=4, sticky=tk.N + tk.S + tk.E, pady=(10,0), padx=(10,0)) 119 tree1.config(yscrollcommand=lambda f, l: ybar1.set(f, l)) 120 121 btn_AddColumn = ttk.Button(frm2, text = "→") 122 btn_AddColumn.grid(row=3, column=4, columnspan=2, sticky=tk.E + tk.W + tk.N + tk.S, pady=(10,0)) 123 124 lstbox = tk.Listbox(frm2, bg="black", exportselection=False, foreground="white", font=("Arial", 16)) 125 lstbox.grid(row=3, column=6, rowspan=4, columnspan=4, sticky=tk.E + tk.W + tk.N + tk.S, pady=(10,0), padx=(0,10)) 126 127 ybar2 = ttk.Scrollbar(frm2, orient=tk.VERTICAL, command=lstbox.yview) 128 ybar2.grid(row=3, column=9, rowspan=4, sticky=tk.N + tk.S + tk.E, pady=(10,0), padx=(0,10)) 129 lstbox.config(yscrollcommand=lambda f, l: ybar2.set(f, l)) 130 131 xbar2 = ttk.Scrollbar(frm2, orient=tk.HORIZONTAL, command=lstbox.xview) 132 xbar2.grid(row=6, column=6, columnspan=4, sticky=tk.S + tk.E + tk.W, padx=(0,10)) 133 lstbox.config(xscrollcommand=lambda f, l: xbar2.set(f, l)) 134 135 btn_Up = ttk.Button(frm2, text = "↑") 136 btn_Up.grid(row=4, column=4, columnspan=2, sticky=tk.E + tk.W + tk.N + tk.S) 137 138 btn_Down = ttk.Button(frm2, text = "↓") 139 btn_Down.grid(row=5, column=4, columnspan=2, sticky=tk.E + tk.W + tk.N + tk.S) 140 141 btn_Cancel = ttk.Button(frm2, text = "←") 142 btn_Cancel.grid(row=6, column=4, columnspan=2, sticky=tk.E + tk.W + tk.N+ tk.S) 143 144 lab_Type = ttk.Label(frm2, text="有無") 145 lab_Type.grid(row=7, column=0, columnspan=2, sticky=tk.E + tk.W + tk.N + tk.S, padx=(0,10)) 146 cmbox_Type = ttk.Combobox(frm2, state="disabled", height=3, font=("Arial", 16)) 147 cmbox_Type.grid(row=8, column=0, columnspan=2, sticky=tk.N + tk.S + tk.E + tk.W, padx=(10, 0)) 148 149 150 tree3 = ttk.Treeview(frm2, show="headings", height=1) 151 tree3.grid(row=9, column=0, columnspan=9, sticky=tk.E + tk.W, padx=(10,0)) 152 153 xbar3 = ttk.Scrollbar(frm2, orient=tk.HORIZONTAL, command=tree3.xview) 154 xbar3.grid(row=10, column=0, columnspan=9, sticky=tk.N + tk.S + tk.E + tk.W, padx=(10,0)) 155 tree3.config(xscrollcommand=lambda f, l: xbar3.set(f, l)) 156 157 btn_ReturnMenu = ttk.Button(frm2, text = "閉じる", command=lambda: change_frame(frm1)) 158 btn_ReturnMenu.grid(row=11, column=8, columnspan=2, sticky=tk.E + tk.W + tk.N + tk.S, pady=(0,10), padx=(0,10)) 159 160 # 161 frm3 = ttk.Frame(root, name="frm3") 162 frm3.grid_rowconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1) 163 frm3.grid_columnconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1, minsize=40) 164 frm3.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S) 165 166 lbfrm1 = ttk.LabelFrame(frm3, text="対応表", labelanchor="n") 167 lbfrm1.grid(row=1, column=0, rowspan=5, columnspan=10, sticky=tk.W + tk.E + tk.N + tk.S, padx=(10,10)) 168 169 list_tmp1 = [1,2,3,4,5] 170 cmbox_Tbl1 = ttk.Combobox(frm3, height=3, font=("Arial", 16), state="readonly", values=list_tmp1) 171 cmbox_Tbl1.grid(row=2, column=1, columnspan=8, sticky=tk.E + tk.W, pady=(10,0), padx=(10,10)) 172 173 frmTmp = ttk.Frame(frm3, name="frmTmp") 174 frmTmp.grid(row=3, column=1, columnspan=8, sticky=tk.E + tk.W + tk.N + tk.S, padx=(10,10), pady=(10,0)) 175 176 lab_Select = ttk.Label(frmTmp, text="種類", font=("Arial", 11)) 177 lab_Select.grid(row=0, column=1, sticky=tk.E + tk.W) 178 179 180 btn_Select = ttk.Button(frm3, text = "選択") 181 btn_Select.grid(row=4, column=1, columnspan=1, sticky=tk.E + tk.W, padx=(10,0), pady=(0,10)) 182 183 btn_TblM = ttk.Button(frm3, text = "編集", command=generate_subwindow1) 184 btn_TblM.grid(row=5, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10)) 185 186 lbfrm2 = ttk.LabelFrame(frm3, text="定義", labelanchor="n") 187 lbfrm2.grid(row=6, column=0, rowspan=5, columnspan=10, sticky=tk.W + tk.E + tk.N + tk.S, padx=(10,10), pady=(20,0)) 188 189 list_tmp2 = [1,2,3,4,5] 190 cmbox_Tbl2 = ttk.Combobox(frm3, height=3, font=("Arial", 16), state="readonly", values=list_tmp2) 191 cmbox_Tbl2.grid(row=7, column=1, columnspan=8, sticky=tk.E + tk.W, pady=(30,0), padx=(10,10)) 192 193 btn_ConvM = ttk.Button(frm3, text = "追加変更") 194 btn_ConvM.grid(row=8, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10)) 195 196 btn_Inq = ttk.Button(frm3, text = "一覧参照") 197 btn_Inq.grid(row=9, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10)) 198 199 btn_ReturnMenu = ttk.Button(frm3, text = "閉じる", command=lambda: change_frame(frm1)) 200 btn_ReturnMenu.grid(row=11, column=8, sticky=tk.E + tk.W, padx=(0,10)) 201 202 frm1.tkraise() 203 204if __name__ == "__main__": 205 root = tk.Tk() 206 adjust_windowsize1(root) 207 root.title("勉強") 208 root.grid_columnconfigure([0,1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1) 209 root.grid_rowconfigure([0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1) 210 root.resizable(0,0) 211 root.protocol('WM_DELETE_WINDOW', (lambda: 'pass')()) 212 root["cursor"] = "hand2" 213 generate_frame(root) 214 root.mainloop()
調べたこと、試したことを質問に追記していただけませんか。
自分でプログラミングしないタイプですか。
本文が文字制限数の10000文字ギリギリの状態なので、こちらに自分が試したことを記載します。(問い合わせ掲載時、試行錯誤して10000文字以内にどうにか収めました)
問題になっているフォーム画面とは 関係のないフレームのコードをはしょると デザインが極端に変わってしまい 陥っている事象を再現出来ませんでした。rootのWindowの上で、二つのフレームを使い分ける仕様で進めてきたので、互いの構造が相互に作用して デザインが保たれているのかな、と推察しています。
問題のフォーム画面は 上記と異なる新たなダイアログの上でのフレーム配置なので、影響を受けないと思っていたんですが やはり何かが作用してしまっているようで。
ツリービューの1行あたりの高さを統一にすような記述が必要なのかな?
回答1件
あなたの回答
tips
プレビュー