私のcheckbutton
はボタンで上書きされています。ボタンにx axis
とy axis
を与えるには?tkinterのチェックボタンの上書きを避ける方法
l.pack()
の代わりにl.place()
を使用しようとしましたが、何も返されません。この上書きを避けるには、l.pack()
の代わりに何を使用する必要がありますか?
コード:
checkbutton
べき秒:
import tkinter as tk
import os
import tkinter.filedialog
class ScrolledFrame(tk.Frame):
def __init__(self, parent, vertical=True, horizontal=False):
super().__init__(parent)
self._canvas = tk.Canvas(self)
self._canvas.grid(row=0, column=0)
self._vertical_bar = tk.Scrollbar(self, orient="vertical",
command=self._canvas.yview)
if vertical:
self._vertical_bar.grid(row=0, column=1, sticky="ns")
self._canvas.configure(yscrollcommand=self._vertical_bar.set)
self._horizontal_bar = tk.Scrollbar(self, orient="horizontal",
command=self._canvas.xview)
if horizontal:
self._horizontal_bar.grid(row=1, column=0, sticky="we")
self._canvas.configure(xscrollcommand=self._horizontal_bar.set)
self.frame = tk.Frame(self._canvas)
self._canvas.create_window((0, 0), window=self.frame, anchor="nw")
self.frame.bind("<Configure>", self.resize)
def resize(self, event=None):
self._canvas.configure(scrollregion=self._canvas.bbox("all"))
#This is not in class
def call():
# add to scrolled frame
data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't']
variables = []
# add widgets to scrolled frame - as parent you have to use `sf.frame` instead of `sf`
for txt in data:
var = tk.IntVar()
variables.append(var)
l = tk.Checkbutton(sf.frame, text=txt, variable=var)
l.pack()
root = tk.Tk()
sf = ScrolledFrame(root)
sf.pack()
btn1 = tkinter.Button(root, text="Source Path", command = call)
btn1.place(x = 0,y = 0)
ent1 = tkinter.Entry(root)
ent1.place(x = 100,y = 0,width = 200,height=25)
btn1 = tkinter.Button(root, text="destination")
btn1.place(x = 0,y = 40)
ent1 = tkinter.Entry(root)
ent1.place(x = 100,y = 40,width = 200,height=25)
root.mainloop()
誤った出力:出力リレー期待
Destination Button
の下のタルト。
異なるレイアウト方法を1つのコンテナ内に混ぜてはいけません**。 '.place'メソッドはうまく動作しません。' .grid'を使うことをお勧めします。正しく使うのがずっと簡単です。 –
私は試しましたが(l.grid(sticky = "w"))、私は同じ結果をPM2Ringで取得しています – sam
すべてのウィジェット、checkbuttonsだけでなく 'btn1'と' 'ent1'。これは、ボタンと項目がパックされたチェックボタンと重複して配置されるためです。 –