2017-03-16 11 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() 

Die Ausgabe kommt im Terminal, von wo ich den Code leite Ich brauche die Ausgabe in GUI-Schnittstelle.Druckausgabe in GUI-Schnittstelle Tkinter Python

Danke.

+1

Ich bin neu in GUI Dinge, wie kann ich es tun? Danke für die Anleitung. –

Antwort

1

Mit Drucken wird nur auf das Terminal oder ein fp gedruckt. Sie können ein neues Label erstellen, um es auf der GUI auszudrucken.

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() 

EIN BEISPIEL FÜR IHREN KOMMENTAR

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

Hallo @abccd bro, \t für nur ein Beispiel, was passiert, wenn ich: für x im Bereich (0,9): Drucken x und ich möchte den Wert von x in der GUI zu drucken? Wie werde ich es tun? –

+0

Nun .. Sie können meine neue Bearbeitung @AnandVyas überprüfen. Wenn ich mich nicht irre, erzeugt das eine Reihe von Labels von 0 bis 8. (Ich kann es jetzt nicht ausprobieren) – abccd

+0

Danke, es hat funktioniert! Aber der Druckfluss ist schlecht, wenn ich 200 Zahlen in einer Zeile drucke, wird der ganze Desktop voll, was soll ich tun? –

0

Ich glaube, Sie haben nichts Ihre "Hey whatsup bro, i am doing something very interresting." in setzen. In tkinter Sie so etwas wie ein Etikett benötigen Text löschen, oder Sie einen neuen def zu erstellen und es zu definieren, was die Taste zu tun hat, wenn jemand darauf klicken.

+0

für nur ein Beispiel, was passiert, wenn ich: 'für x im Bereich (0,9): Drucken x' und ich möchte den Wert von x in der GUI drucken? Wie werde ich es tun? irgendwelche Beispiele mit Codes? –