0
Tkinter (Python 2.5.1 사용)에서 볼 수있는 문제는 grid() 메소드를 사용하여 요소를 추가 할 때 새로운 행을 만드는 대신 위에 쌓아 놓는 것입니다. 코드가 실행되지만 위젯은 모두 응용 프로그램의 중앙에 두 행으로 쌓여 있습니다. 왜 이런 일이 일어나는 걸까요?Tkinter 위젯이 스택 됨
from Tkinter import *
import random
class Application(Frame):
"""Define Application's constructor"""
def __init__(self, master):
"""Initialize the Frame"""
Frame.__init__(self, master)
self.grid()
self.create_widgets()
#Create the widgets
def create_widgets(self):
self.lblTitle = Label(self, text="Build Your Own Burger")
self.lblTitle.grid(row=0)
self.lblBurgerImg = Label(self, image=PhotoImage(file="burger.gif"))
self.lblTitle.grid(row=1)
self.lblName = Label(self, text="Name:")
self.lblName.grid(row=2, column=0, columnspan=2, sticky=W)
self.entryName = Entry(self)
self.entryName.grid(row=2, column=1, columnspan=2, sticky=W)
self.lblToppings = Label(self, text = "Toppings:")
self.lblTitle.grid(row=3, column=0, sticky=W, columnspan=5, sticky=W)
self.chkCheese = Checkbutton(self, text="cheese")
self.chkCheese.grid(row=3, column=1, sticky=W, columnspan=5, sticky=W)
#main program
#create a root window
root = Tk()
#assign a title for the GUI
root.title("Order Up!")
#Define size of root window
root.geometry("700x700")
#create an instance of your application
app = Application(root)
#start the event loop
root.mainloop()
와우, 나는 그것을 잡지 못했다고 나는 믿을 수 없다. 고마워, 브라이언! 그것을 고치고 난 후에, 나는 지금 나의 burger 이미지가 있어야하는 빈 공간을보고있다. python 스크립트와 같은 디렉토리에있는 .gif 파일입니다. 코드가 올바르게 표시 되려면 코드를 추가해야합니까? – KongMD
밝혀졌습니다. 이미지를 개별적으로 선언하고 너비와 높이 특성을 추가하는 것만으로도 충분했습니다. 다시 한번 감사드립니다 :) – KongMD