2013-04-07 3 views
0

저는 tkinter를 처음 접했고 그 이미지 아래에 4 개의 버튼이있는 이미지가있는 GUI를 만들려고했습니다. 대답을 선택하십시오. 그러나 내가 지금까지 가지고있는 코드로는 왼쪽 상단 모서리에 머무르는 것처럼 보이고 이미지 아래로 움직이지 않는 버튼이 있습니다. 아무도이 해결책을 알지 못합니까?Tkinter : 그리드 레이아웃의 버튼 위의 이미지 얻기

import Tkinter as tk 
from Tkinter import * 
from Tkinter import PhotoImage 

root = Tk() 

class Class1(Frame): 

    def __init__(self, master): 
     Frame.__init__(self, master) 
     self.grid() 

     self.master = master   
     self.question1_UI() 

    def question1_UI(self): 

     self.master.title("GUI")   

     gif1 = PhotoImage(file = 'Image.gif') 

     label1 = Label(image=gif1) 
     label1.image = gif1 
     label1.grid(row=1, column = 0, columnspan = 2, sticky=NW) 

     questionAButton = Button(self, text='Submit',font=('MS', 8,'bold')) 
     questionAButton.grid(row = 2, column = 1, sticky = S) 
     questionBButton = Button(self, text='Submit',font=('MS', 8,'bold')) 
     questionBButton.grid(row = 2, column = 2, sticky = S) 
     questionCButton = Button(self, text='Submit',font=('MS', 8,'bold')) 
     questionCButton.grid(row = 3, column = 3, sticky = S) 
     questionDButton = Button(self, text='Submit',font=('MS', 8,'bold')) 
     questionDButton.grid(row = 3, column = 4, sticky = S) 



def main(): 


    ex = Class1(root) 
    root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), 
    root.winfo_screenheight()))   
    root.mainloop() 


if __name__ == '__main__': 
    main() 

답변

1

label1의 부모로 self을 사용하고 있지 않습니다. 게다가 그리드 관리자는 행 0에서 시작합니다 :

def question1_UI(self): 
    # ... 
    label1 = Label(self, image=gif1) 
    label1.image = gif1 
    label1.grid(row = 0, column = 0, columnspan = 2, sticky=NW) 

    questionAButton = Button(self, text='Submit',font=('MS', 8,'bold')) 
    questionAButton.grid(row = 1, column = 0, sticky = S) 
    questionBButton = Button(self, text='Submit',font=('MS', 8,'bold')) 
    questionBButton.grid(row = 1, column = 1, sticky = S) 
    questionCButton = Button(self, text='Submit',font=('MS', 8,'bold')) 
    questionCButton.grid(row = 2, column = 0, sticky = S) 
    questionDButton = Button(self, text='Submit',font=('MS', 8,'bold')) 
    questionDButton.grid(row = 2, column = 1, sticky = S) 
+0

대단히 감사합니다! – user2254822