我期望的结果是有一个python窗口,两个按钮“显示信息”“退出”相邻,并有“显示信息”按钮显示我的姓名和地址3条单独的行 ,然后在单击“退出”时停止该程序。我几乎在那里 - 文本虽然都在一行。需要显示在3行而不是1行
在此先感谢。
# This program will demonstrate a button widget within a dialog box
# that shows my information.
# Call TK interface
import tkinter
# Call message box
import tkinter.messagebox
# Create class for GUI.
class MyGUI:
def __init__(self):
#Create the main window widget.
self.main_window = tkinter.Tk()
#Create button widget 1.
self.my_button = tkinter.Button(self.main_window, \
text='Show Info', \
command=self.show_info)
#Creat a quit button.
self.quit_button = tkinter.Button(self.main_window, \
text='Quit', \
command=self.main_window.destroy)
# Pack the buttons.
self.my_button.pack(side='left')
self.quit_button.pack(side='left')
#Enter the tkinter main loop.
tkinter.mainloop()
#The do_somethings will be defined.
def show_info(self):
tkinter.messagebox.showinfo('Text', \
'My Name'
'123 Any Rd'
'Town Fl, 12345')
my_gui = MyGUI()
这工作完美 - 非常感谢您的及时回应。 – user3780539