你能把Python脚本转换成GUI格式吗?

你能把Python脚本转换成GUI格式吗?,python,python-3.x,Python,Python 3.x,我对python完全陌生,我一直在使用一个脚本来生成令牌(它还使用其他脚本的导入),但现在我想在GUI上使用它,而不是在cmd上。这可能吗?我曾尝试使用一个示例GUI并向其添加元素,但似乎无法理解输出部分 main.py: from encode_token import Encoder, Shared from decode_token import Decoder import codecs dkey = (input("enter hex:\n")) start_

我对python完全陌生,我一直在使用一个脚本来生成令牌(它还使用其他脚本的导入),但现在我想在GUI上使用它,而不是在cmd上。这可能吗?我曾尝试使用一个示例GUI并向其添加元素,但似乎无法理解输出部分

main.py:

from encode_token import Encoder, Shared
from decode_token import Decoder
import codecs



dkey = (input("enter hex:\n"))
start_code = int(input("enter Starting code:\n"))

device_count = int(input("enter last count:\n"))
days_to_activate = int(input("enter days to activate:\n"))


if __name__ == '__main__':
    print('Generating code to: '+device_key_hex+' and starting code '+str(device_starting_code)+'. ')
  
    new_count, token = Encoder.generate_standard_token(
        starting_code=start_code,
        key=codecs.decode(dkey, 'hex'),
        value=days_to_activate,
        count=device_count,
        restricted_digit_set=False,
        mode=Shared.TOKEN_TYPE_ADD_TIME
    )

    print(token)

    value, count, type = Decoder.get_activation_value_count_and_type_from_token(
        starting_code=start_code,
        key=codecs.decode(dkey, 'hex'),
        token=token,
        last_count=device_count
    )
    print(value, count, type)

因为你是新来的,所以可能值得一看,它是为制作基本的脚本到GUI应用程序而设计的,这些应用程序可能会非常好,听起来可能适合你。对于一些更定制但更容易进入的东西,可以尝试一下它的强大功能,但不难掌握。当然也有,但如果您是Python的新手,使用起来就不那么容易了,尽管它肯定比其他一些选项更容易。

尝试使用PySimpleGUI为您构建GUI,应该确认所有导入都正常。 请参阅关于PySimpleGUI的文档

可能通过以下方式安装PySimpleGUI

pip安装PySimpleGUI
#来自encode_令牌导入编码器,共享
#从解码\令牌导入解码器
#导入编解码器
#导入共享
将PySimpleGUI导入为sg
def更新结果(令牌、值、计数、类型):
窗口['token'].更新(str(token))
窗口['value'].更新(str(value))
窗口['count'].更新(str(count))
窗口['type'].更新(str(type)))
sg.theme(“暗蓝色3”)
设置选项(字体=('Courier New',16))
布局=[
#输入
[sg.Text('Hex Code'),sg.Input(key='dkey')],
[sg.Text('Starting Code')、sg.Input(key='start_Code')],
[sg.Text('Last Count')、sg.Input(key='device_Count')],
[sg.Text('Days to Activate')、sg.Input(key='Days to Activate'),
#由按钮生成的事件
[sg.按钮(“生成”)],
#卧式分离器
[sg.水平分离器()],
#输出
[sg.Text('Token:'),sg.Text(size=(0,1),key='Token'),
[sg.Text('Value:')、sg.Text(size=(0,1)、key='Value'),
[sg.Text('Count:')、sg.Text(size=(0,1)、key='Count'),
[sg.Text('Type:')、sg.Text(size=(0,1)、key='Type'),
]
窗口=sg.窗口(“标记”,布局)#窗口布局和标题
尽管如此:
事件,值=window.read()#获取事件和元素值
如果事件==sg.WINDOW_CLOSED:#如果单击了窗口的close按钮
打破
elif事件==“生成”:#如果单击“生成”按钮
#获取所有输入
尝试:
start_code=int(值['start_code'])#如果不是整数
除:
更新#u结果(*(“错误的启动代码!”)*4))#显示警告信息
持续
dkey=值['dkey']
设备计数=值['device\u count']
days_to_activate=值['days_to_activate']
#从输入中获取结果
新建\u计数,令牌=编码器。生成\u标准\u令牌(
启动代码=启动代码,
key=编解码器.解码(dkey,'hex'),
值=激活的天数,
计数=设备计数,
受限数字集=假,
模式=共享。令牌类型添加时间
)
值、计数、类型=解码器。从\u令牌获取\u激活\u值\u计数\u和\u类型\u(
启动代码=启动代码,
key=编解码器.解码(dkey,'hex'),
令牌=令牌,
上次计数=设备计数
)
#显示输出
更新结果(令牌、值、计数、类型)
window.close()