消息框中的tkinter显示输出

时间:2016-07-04 11:49:09

标签: python tkinter messagebox display

我想显示我问的条目的结果。我设法在控制台中显示结果,但没有显示tkMessageBox.showinfo打开的消息。 相反,我得到了数值。

,这很奇怪

以下是我的代码。

    #!/usr/bin/env python
from Tkinter import *
import tkSimpleDialog
import tkMessageBox
import time
import requests
def show_entry_fields():
print("loginS3: %s \n secretpasseS3: %s \n endpointS3: %s \n " % (ChamploginS3.get(), ChampsecretpasseS3.get(), ChampsendpointS3.get()))
ChamploginS3.delete(0,END)
ChampsecretpasseS3.delete(0,END)
ChampsendpointS3.delete(0,END)
tkMessageBox.showinfo (title='inputs for S3', message="are those inputs correct ? " '\n' 'loginS3: %s \n secretpasseS3: %s \n endpointS3: %s \n ' %( ChamploginS3,ChampsecretpasseS3,ChampsendpointS3))
fenetre0 = Tk()
fenetre0.title('S3 brower perso')
fenetre0.geometry("380x100")
Label1 = Label(fenetre0, text = 'loginS3', fg = 'blue').grid (row=0)
Label2 = Label(fenetre0, text = 'secretpasseS3', fg = 'red').grid (row=1)
Label3 = Label(fenetre0, text = 'endpointS3', fg = 'purple').grid (row=2)
loginS3= StringVar()
ChamploginS3 = Entry(fenetre0, textvariable= loginS3, bg ='bisque', fg='maroon')
secretpasseS3= StringVar()
ChampsecretpasseS3 = Entry(fenetre0, textvariable= secretpasseS3, show='*', bg ='bisque', fg='maroon')
endpointS3= StringVar()
ChampsendpointS3 = Entry(fenetre0, textvariable= endpointS3, bg ='bisque', fg='maroon')
ChamploginS3.grid(row=0, column=1)
ChampsecretpasseS3.grid(row=1, column=1)
ChampsendpointS3.grid(row=2, column=1)
Bouton1 = Button(fenetre0, text = 'END', command = fenetre0.destroy).grid(row=3, column=0, sticky=W, pady=4)
Bouton2 = Button(fenetre0, text = 'SHOW', command = show_entry_fields).grid(row=3, column=1, sticky=W, pady=4)
fenetre0.mainloop()

1 个答案:

答案 0 :(得分:1)

您需要解决两件事:

首先,不要删除这些条目的内容。这意味着您必须删除这3行

  ChamploginS3.delete(0,END)
  ChampsecretpasseS3.delete(0,END)
  ChampsendpointS3.delete(0,END)

其次,使用get()方法访问条目小部件的内容。这意味着您需要更改此行:

tkMessageBox.showinfo (title='inputs for S3', message="are those inputs correct ? " '\n' 'loginS3: %s \n secretpasseS3: %s \n endpointS3: %s \n ' %( ChamploginS3,ChampsecretpasseS3,ChampsendpointS3))

要:

tkMessageBox.showinfo (title='inputs for S3', message="are those inputs correct ? " '\n' 'loginS3: %s \n secretpasseS3: %s \n endpointS3: %s \n ' %(ChamploginS3.get(),ChampsecretpasseS3.get(),ChampsendpointS3.get()))

演示:

完成上述操作后,您将得到您的期望:

enter image description here