2017-03-16 8 views
0
from Tkinter import * 

def printSomething(): 
    print "Hey whatsup bro, i am doing something very interresting." 

root = Tk() 

button = Button(root, text="Print Me", command=printSomething) 
button.pack() 

root.mainloop() 

コードが実行されている場所から出力が来ている GUIインターフェイスで出力が必要です。GUIインターフェイスで出力を出力する

ありがとうございました。

+1

私はGUIのもので新しいですFORの例では、私はそれをどのように行うことができますか?ガイドに感謝します。 –

答えて

1

端末またはfpへの印刷のみの印刷を使用します。新しいラベルを作成してGUIに「印刷」することができます。

from Tkinter import * 

def printSomething(): 
    # if you want the button to disappear: 
    # button.destroy() or button.pack_forget() 
    label = Label(root, text= "Hey whatsup bro, i am doing something very interresting.") 
    #this creates a new label to the GUI 
    label.pack() 

root = Tk() 

button = Button(root, text="Print Me", command=printSomething) 
button.pack() 

root.mainloop() 

コメント

from Tkinter import * 

def printSomething(): 
    # if you want the button to disappear: 
    # button.destroy() or button.pack_forget() 
    for x in range(9): # 0 is unnecessary 
     label = Label(root, text= str(x)) 
    # this creates x as a new label to the GUI 
     label.pack() 

root = Tk() 

button = Button(root, text="Print Me", command=printSomething) 
button.pack() 

root.mainloop() 
+0

こんにちは@abccd bro、\t もし私がするならば:xの範囲(0,9):print xとxの値をGUIで印刷したいですか?どうすればいいですか? –

+0

まあ、あなたは私の新しい編集@AnandVyasをチェックアウトすることができます。私が間違っていなければ、これは0から8までのラベルの行を作成します(私は今試してみることができません) – abccd

+0

おかげでそれは働いた!しかし、私が何をすべきなのか、デスクトップ全体が一杯に200個の数字を印刷すると、印刷の流れが悪いですか? –

0

あなたは"Hey whatsup bro, i am doing something very interresting."を置くことは何もないと思います。tkinterでは、テキストを書き込むためのラベルが必要です。あるいは、新しいdefを作成して、誰かがクリックした場合にボタンが何をしなければならないかを定義します。

+0

ちょっとした例のために: 'for x in range(0,9):print x'とxの値をGUIで印刷したいのですが?どうすればいいですか?コードの例は? –

関連する問題