fork download
  1. from tkinter import *
  2. import re
  3. def c10to2(x):
  4. if re.match(r'\d+\b',x):
  5. s = ''
  6. x = int(x)
  7. while x >=1:
  8. s+=str(x%2)
  9. x//=2
  10. return s[::-1]
  11. else:
  12. return 'ERROR'
  13. def c2to10(x):
  14. if re.match(r'[01]+\b',x):
  15. x = str(x)
  16. y = 0
  17. n = len(x)-1
  18. for i in x:
  19. y+=int(i)*(2**n)
  20. n-=1
  21. return y
  22. return 'ERROR'
  23. def etake(e):
  24. number = my_number.get()
  25. x = my_sys.get()
  26. y = target_sys.get()
  27. if x == '10' and y == '2':
  28. my_solve.delete(0,END)
  29. my_solve.insert(END,c10to2(number))
  30. elif x == '2' and y == '10':
  31. my_solve.delete(0,END)
  32. my_solve.insert(END,c2to10(number))
  33. else:
  34. return 'ERROR'
  35.  
  36. w = Tk()
  37. w.title('Системы счисления')
  38. w.geometry('280x145')
  39. w.resizable(0,0)
  40. first_text = Label(w,text='Перевести из ',font=14)
  41. second_text = Label(w,text='в',font=14)
  42. my_sys = Entry(w,width=3)
  43. target_sys = Entry(w,width=3)
  44. my_number=Entry(w,width=16)
  45. my_solve=Entry(w,width=16)
  46. b = Button(w,text='Go!',bg='pink',height=2,width=5,command=lambda event='<Button-1>': etake('<Button-1>')) # Теперь результат выдаётся как по нажатию на кнопку "Go", так и...
  47. my_number.bind('<Return>',etake) # ... по простому нажатию на Enter
  48.  
  49. first_text.place(x=6,y=10)
  50. my_sys.place(x=115,y=10)
  51. second_text.place(x=140,y=10)
  52. target_sys.place(x=165,y=10)
  53. my_number.place(x=6, y=70)
  54. b.place(x=115,y=65)
  55. my_solve.place(x=170,y=70)
  56.  
  57. w.mainloop()
Runtime error #stdin #stdout #stderr 0.04s 25664KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 36, in <module>
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable