Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: Darui803 en 9 Septiembre 2015, 19:25 pm



Título: Problema en python
Publicado por: Darui803 en 9 Septiembre 2015, 19:25 pm
Buenas tengo un error en python2.7 trabajo en Debian 8.2 con KDE.

Código
  1. import Tkinter
  2.  
  3. apl = Tkinter.Tk()
  4. texto = Label(apl, text="Hola Mundo!")
  5. texto.pack()
  6. apl.mainloop()

Este es el error

No protocol specified
No protocol specified
Traceback (most recent call last):
 File "grafico.py", line 3, in <module>
   apl = Tkinter.Tk()
 File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in __init__
   self.tk = __tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0"



Título: Re: Problema en python
Publicado por: DeMoNcRaZy en 9 Septiembre 2015, 19:48 pm
Prueba así:

Código
  1. #Ventana
  2. from Tkinter import *
  3. import tkMessageBox
  4.  
  5. def suma():
  6.  try:
  7.    n1 = float(nombre_entry.get())
  8.    n2 = float(last_entry.get())
  9.    resultado = n1 + n2
  10.  
  11.    tkMessageBox.showinfo('Mensaje', 'El resultado de la suma es: %2.f' %resultado)
  12.  except ValueError:
  13.    tkMessageBox.showinfo('Error', 'El valor introducido no es un numero.')
  14.  
  15.  nombre_entry.delete(0, 20)
  16.  last_entry.delete(0, 20)
  17.  
  18. ventana = Tk()
  19.  
  20. ventana.title('Ventana en Python')
  21. ventana.geometry("250x160")
  22. ventana.resizable(width=FALSE, height=FALSE)
  23.  
  24. widget = Label(ventana, text='Numero 1: ')
  25. widget.grid(row=1,column=1)
  26. nombre_str = StringVar()
  27. nombre_entry = Entry(ventana,textvariable=nombre_str)
  28. nombre_entry.grid(row=1,column=2)
  29.  
  30. last_label= Label(ventana,text="Numero 2: ")
  31. last_label.grid(row=2,column=1)
  32. last_str = StringVar()
  33. last_entry = Entry(ventana,textvariable=last_str)
  34. last_entry.grid(row=2,column=2)
  35.  
  36. finish = Button(ventana,text="Sumar", command = suma,width=15)
  37. finish.grid(row=4,column=2)
  38.  
  39. ventana.mainloop()

Es un pequeño Script que hice hace un tiempo.. y suma los valores como una calculadora.

Creo que hace lo que buscas.
Espero que te sirva.

Saludos.


Título: Re: Problema en python
Publicado por: Darui803 en 10 Septiembre 2015, 00:16 am
No funciono sale lo mismo :c