GUI를 생성하는 코드를 작성했습니다. 이제 코드를 실행할 때마다 기본 GUI 창과 아무것도없는 작은 창이 추가로 생성됩니다. 작은 창을 닫으면 큰 주 창이 사라집니다. 지금 비슷한 문제가있는 다른 게시물을 읽었지만 내 코드에서 오류의 위치를 확인할 수 없었습니다.Extra Tkinter GUI 팝업
: 도와주세요
는 질문을 따르십시오 : 어떻게 회색 지루한 색상보다는 배경 이미지를 추가?
#%% GUI Interface
import Tkinter as tk
from tkFont import Font
from PIL import ImageTk, Image
from Tkinter import END
#This creates the main window of an application
window = tk.Toplevel()
window.title("Sat Track")
window.geometry("1200x800")
window.configure(background='#f0f0f0')
#Imports the pictures.
pic1 = "Globeview.png"
pic2 = "MercatorView.png"
pic3 = "currentweathercroppedsmall.png"
pic4 = "GECurrentcroppedsmall.png"
#Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
img1 = ImageTk.PhotoImage(Image.open(pic1))
img2 = ImageTk.PhotoImage(Image.open(pic2))
img3 = ImageTk.PhotoImage(Image.open(pic3))
img4 = ImageTk.PhotoImage(Image.open(pic4))
header = tk.Label(window, text="Satellite Control Center", font=Font(size=40))
header.pack()
toprow = tk.Frame(window)
infobox = tk.Text(toprow, width=50, height=7, font=("Calibri",12))
infobox.pack(side = "left")
infobox.insert(END,"Current information for:"+spacer+name +'\n'+
"Time:" +space+times+ '\n'+
"Longitude:"+space +x_long+ '\n'+
"Latitude:" +space+x_lat+ '\n'+
"Altitude:" +space+alt+space+ "[km]"+'\n'+
"Velocity:" +space+vel+space+ "[km/s]" + '\n'+
"Spatial Resolution: "+space +spat+space+ "[Pixels pr. m]"
)
toprow.pack()
midrow = tk.Frame(window)
globeview = tk.Label(midrow, image = img1)
globeview.pack(side = "left") # the side argument sets this to pack in a row rather than a column
mercatorview = tk.Label(midrow, image = img2)
mercatorview.pack(side = "left")
midrow.pack() # pack the toprow frame into the window
bottomrow = tk.Frame(window)
currentweather= tk.Label(bottomrow, image = img3)
currentweather.pack(side = "left")
gearth = tk.Label(bottomrow, image = img4)
gearth.pack(side = "left")
bottomrow.pack()
#Start the GUI
window.mainloop()
제거하면 모듈을 호출 할 수 없다는 오류가 표시됩니다. 그래, 주로 3을 사용하지만이 작업에서 python2를 사용해야합니다. py2 imo에서 tkinter를 사용하는 엉덩이에 큰 고통이 있습니다. – Kongstad
네, 가져온 방법 때문입니다. 'tkinter를 tk로 가져 오기'하고 'window = tk.Tk()'하면 어떻게됩니까? –
또한 필자는 필자의 대답을 편집하여 필자의 가져 오기가 귀하의 것을 더 잘 반영하도록하였습니다 (대문자 사용 제외). 희망이 도움이됩니다! :) –