2017-11-21 2 views
1

checkbutton이 버튼으로 덮어 쓰고 있습니다. 버튼에 x axisy axis을주는 방법은 무엇입니까?tkinter에서 체크 버튼 덮어 쓰기를 피하는 방법

l.pack() 대신 l.place()을 사용하려고했지만 아무 것도 반환하지 않습니다. 이 덮어 쓰기를 방지하려면 l.pack() 대신 무엇을 사용해야합니까?

코드 :

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() 

잘못된 출력 :

enter image description here

예상 OUPUT :

checkbutton해야의 Destination Button 아래의 타르트.

+0

** 하나의 컨테이너 안에 다른 레이아웃 방법을 혼합해서는 안됩니다 **. '.place' 메쏘드는 잘 작동하지 않습니다. 여러분이'.grid'를 사용할 것을 권합니다. 올바르게 사용하는 것이 훨씬 쉽습니다. –

+0

나는 시도했다. (l.grid (sticky = "w")). 그러나 같은 결과를 얻고있다. @ PM2Ring – sam

+0

모든 위젯, 체크 버튼뿐만 아니라'btn1'과' 'ent1'. 이는 버튼과 항목이 압축 된 체크 버튼과 겹치기 때문에 배치됩니다. –

답변

1

의견에서 언급했듯이 다양한 레이아웃을 혼합하지 마십시오.
그러면 생성하려는 프레임에 입력 상자와 단추가있는 것이 좋습니다. 버튼을 클릭하면

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) 

     btn1 = tkinter.Button(root, text="Source Path", command = call) 
     btn1.pack() 

     ent1 = tkinter.Entry(root) 
     ent1.pack() 

     btn1 = tkinter.Button(root, text="destination") 
     btn1.pack() 

     ent1 = tkinter.Entry(root) 
     ent1.pack() 
     self.pack() 

    def resize(self, event=None): 
     self._canvas.configure(scrollregion=self._canvas.bbox("all")) 


def call(): 
    # add components 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) 
root.mainloop() 

귀하의 틱 상자가 나타납니다 : 원하는 경우 여기

내가 제안 무엇을, 다른 레이아웃으로 변경할 수 있습니다.

+0

고맙습니다. – sam

+0

기꺼이 도와 드리겠습니다. –

관련 문제