import tkinter
import tkinter.messagebox
class checkbutton:
def __init__(self):
self.main = tkinter.Tk()
self.top = tkinter.Frame(self.main)
self.bot = tkinter.Frame(self.main)
self.cb1v = tkinter.IntVar()
self.cb2v = tkinter.IntVar()
self.cb3v = tkinter.IntVar()
self.cb1v.set(0)
self.cb2v.set(0)
self.cb3v.set(0)
self.cb1 = tkinter.Checkbutton(self.top, text = 'Option 1', variable = self.cb1v)
self.cb2 = tkinter.Checkbutton(self.top, text = 'Option 2', variable = self.cb2v)
self.cb3 = tkinter.Checkbutton(self.top, text = 'Option 3', variable = self.cb3v)
self.cb1.pack()
self.cb2.pack()
self.cb3.pack()
self.calbutton = tkinter.Button(self.bot, text = 'ok', command = self.show)
self.quit = tkinter.Button(self.bot, text = 'quit',command = self.main.destroy)
self.calbutton.pack(side='left')
self.quit.pack(side='left')
tkinter.mainloop()
def show(self):
self.messge = 'you click: '
if self.cb1v.get() == 1:
self.messge = self.messge + '1'
if self.cb2v.get() == 1:
self.messge = self.messge + '2'
if self.cb3v.get() == 1:
self.messge = self.messge + '3'
tkinter.messagebox.showinfo('seletion',self.messge)
gui = checkbutton()
위의 체크 버튼 GUI 프로그램에 대한 코드는 출력을 얻을 것으로 예상했습니다.
하지만 프로그램을 실행 한 후에는 예상치 못한 출력이 나타납니다.
보시다시피 예기치 않은 출력이 공백으로 표시되고 아무것도 표시되지 않습니다. 그 이유를 알고 싶고 내 코드에 문제가 있습니까? 이 문제로 저를 도울 수 있다면 매우 감사하겠습니다.
문제는 self.cb1
또는 cb2
또는 의 부모를 압축하지 않는다는 것 cb3
입니다. 방법 self.top.pack()
에서 해야합니다 __init__
.
def __init__(self):
# code above
self.top.pack()
self.cb1 = tkinter.Checkbutton(self.top, text = 'Option 1', variable = self.cb1v)
self.cb2 = tkinter.Checkbutton(self.top, text = 'Option 2', variable = self.cb2v)
self.cb3 = tkinter.Checkbutton(self.top, text = 'Option 3', variable = self.cb3v)
# code after
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다