from tkinter import *
import re
def c10to2( x) :
if re .match ( r'\d +\b ' , x) :
s = ''
x = int ( x)
while x >= 1 :
s+= str ( x%2 )
x//= 2
return s[ ::-1 ]
else :
return 'ERROR'
def c2to10( x) :
if re .match ( r'[01]+\b ' , x) :
x = str ( x)
y = 0
n = len ( x) -1
for i in x:
y+= int ( i) *( 2 **n)
n-= 1
return y
return 'ERROR'
def etake( e) :
number = my_number.get ( )
x = my_sys.get ( )
y = target_sys.get ( )
if x == '10' and y == '2' :
my_solve.delete ( 0 , END)
my_solve.insert ( END, c10to2( number) )
elif x == '2' and y == '10' :
my_solve.delete ( 0 , END)
my_solve.insert ( END, c2to10( number) )
else :
return 'ERROR'
w = Tk( )
w.title ( 'Системы счисления' )
w.geometry ( '280x145' )
w.resizable ( 0 , 0 )
first_text = Label( w, text= 'Перевести из ' , font= 14 )
second_text = Label( w, text= 'в' , font= 14 )
my_sys = Entry( w, width= 3 )
target_sys = Entry( w, width= 3 )
my_number= Entry( w, width= 16 )
my_solve= Entry( w, width= 16 )
b = Button( w, text= 'Go!' , bg= 'pink' , height= 2 , width= 5 , command= lambda event= '<Button-1>' : etake( '<Button-1>' ) ) # Теперь результат выдаётся как по нажатию на кнопку "Go", так и...
my_number.bind ( '<Return>' , etake) # ... по простому нажатию на Enter
first_text.place ( x= 6 , y= 10 )
my_sys.place ( x= 115 , y= 10 )
second_text.place ( x= 140 , y= 10 )
target_sys.place ( x= 165 , y= 10 )
my_number.place ( x= 6 , y= 70 )
b.place ( x= 115 , y= 65 )
my_solve.place ( x= 170 , y= 70 )
w.mainloop ( )
ZnJvbSB0a2ludGVyIGltcG9ydCAqCmltcG9ydCByZQpkZWYgYzEwdG8yKHgpOgogICAgaWYgcmUubWF0Y2gocidcZCtcYicseCk6CiAgICAgICAgcyA9ICcnCiAgICAgICAgeCA9IGludCh4KQogICAgICAgIHdoaWxlIHggPj0xOgogICAgICAgICAgICBzKz1zdHIoeCUyKQogICAgICAgICAgICB4Ly89MgogICAgICAgIHJldHVybiBzWzo6LTFdCiAgICBlbHNlOgogICAgICAgIHJldHVybiAnRVJST1InCmRlZiBjMnRvMTAoeCk6CiAgICBpZiByZS5tYXRjaChyJ1swMV0rXGInLHgpOgogICAgICAgIHggPSBzdHIoeCkKICAgICAgICB5ID0gMAogICAgICAgIG4gPSBsZW4oeCktMQogICAgICAgIGZvciBpIGluIHg6CiAgICAgICAgICAgIHkrPWludChpKSooMioqbikKICAgICAgICAgICAgbi09MQogICAgICAgIHJldHVybiB5CiAgICByZXR1cm4gJ0VSUk9SJwpkZWYgZXRha2UoZSk6CiAgICBudW1iZXIgPSBteV9udW1iZXIuZ2V0KCkKICAgIHggPSBteV9zeXMuZ2V0KCkKICAgIHkgPSB0YXJnZXRfc3lzLmdldCgpCiAgICBpZiB4ID09ICcxMCcgYW5kIHkgPT0gJzInOgogICAgICAgIG15X3NvbHZlLmRlbGV0ZSgwLEVORCkKICAgICAgICBteV9zb2x2ZS5pbnNlcnQoRU5ELGMxMHRvMihudW1iZXIpKQogICAgZWxpZiB4ID09ICcyJyBhbmQgeSA9PSAnMTAnOgogICAgICAgIG15X3NvbHZlLmRlbGV0ZSgwLEVORCkKICAgICAgICBteV9zb2x2ZS5pbnNlcnQoRU5ELGMydG8xMChudW1iZXIpKQogICAgZWxzZToKICAgICAgICByZXR1cm4gJ0VSUk9SJwoKdyA9IFRrKCkKdy50aXRsZSgn0KHQuNGB0YLQtdC80Ysg0YHRh9C40YHQu9C10L3QuNGPJykKdy5nZW9tZXRyeSgnMjgweDE0NScpCncucmVzaXphYmxlKDAsMCkKZmlyc3RfdGV4dCA9IExhYmVsKHcsdGV4dD0n0J/QtdGA0LXQstC10YHRgtC4INC40LcgJyxmb250PTE0KQpzZWNvbmRfdGV4dCA9IExhYmVsKHcsdGV4dD0n0LInLGZvbnQ9MTQpCm15X3N5cyA9IEVudHJ5KHcsd2lkdGg9MykKdGFyZ2V0X3N5cyA9IEVudHJ5KHcsd2lkdGg9MykKbXlfbnVtYmVyPUVudHJ5KHcsd2lkdGg9MTYpCm15X3NvbHZlPUVudHJ5KHcsd2lkdGg9MTYpCmIgPSBCdXR0b24odyx0ZXh0PSdHbyEnLGJnPSdwaW5rJyxoZWlnaHQ9Mix3aWR0aD01LGNvbW1hbmQ9bGFtYmRhIGV2ZW50PSc8QnV0dG9uLTE+JzogZXRha2UoJzxCdXR0b24tMT4nKSkgIyDQotC10L/QtdGA0Ywg0YDQtdC30YPQu9GM0YLQsNGCINCy0YvQtNCw0ZHRgtGB0Y8g0LrQsNC6INC/0L4g0L3QsNC20LDRgtC40Y4g0L3QsCDQutC90L7Qv9C60YMgIkdvIiwg0YLQsNC6INC4Li4uCm15X251bWJlci5iaW5kKCc8UmV0dXJuPicsZXRha2UpICMgLi4uINC/0L4g0L/RgNC+0YHRgtC+0LzRgyDQvdCw0LbQsNGC0LjRjiDQvdCwIEVudGVyCgpmaXJzdF90ZXh0LnBsYWNlKHg9Nix5PTEwKQpteV9zeXMucGxhY2UoeD0xMTUseT0xMCkKc2Vjb25kX3RleHQucGxhY2UoeD0xNDAseT0xMCkKdGFyZ2V0X3N5cy5wbGFjZSh4PTE2NSx5PTEwKQpteV9udW1iZXIucGxhY2UoeD02LCB5PTcwKQpiLnBsYWNlKHg9MTE1LHk9NjUpCm15X3NvbHZlLnBsYWNlKHg9MTcwLHk9NzApCgp3Lm1haW5sb29wKCk=
stdout
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