2017-02-23 66 views
0

import語句

import from tkinter import * 
import tkinter.simpledialog 
import tkinter.messagebox 
from tkinter import ttk 
from time import strftime 
now = strftime("%x %Z %X") 

設置窗口

root=Tk() 
root.title("ON TOP OF THE WORLD") 
canvas= Canvas(root, width=350, height=250) 
canvas.pack() 
photo=PhotoImage(file='/Users/m/Desktop/TOTW.gif') 
canvas.create_image(0, 0, anchor = NW, image=photo) 

歡迎用戶

tkinter.messagebox.showinfo("Hello,today is", now) 

詢問用戶

name=tkinter.simpledialog.askstring("name","What is your name?") 

輸入過程

output = "Hello, %s! May the only place you find yourself today is on top of the world !" %name 

顯示輸出

tkinter.messagebox.showinfo(now, output) 

CLOSE

def on_closing(): 
    if tkinter.messagebox.askokcancel("Quit", "Do you want to quit?"): 
     root.destroy() 

root.protocol(on_closing) 
root.mainloop() 

我需要關閉幫助還是結束該對話框

+0

那麼..你的問題是什麼?你有什麼錯誤嗎?你期望什麼以及這段代碼如何工作?你應該詳細說明你的問題。 – Lafexlos

回答

0

你可以採取其他兩種方式這,一個退出(),並簡單地結束代碼,或使用在tkinter中調用不同的框架,不管它是關閉還是空白。它將能夠覆蓋已經存在的所有東西