鱼C论坛

 找回密码
 立即注册
查看: 1840|回复: 3

编译后功能不好用

[复制链接]
发表于 2019-11-1 17:03:56 | 显示全部楼层 |阅读模式
10鱼币
import re
import os, sys
try:
    from tkinter import *
except ImportError:  #Python 2.x
    PythonVersion = 2
    from Tkinter import *
    from tkFont import Font
    from ttk import *
    #Usage:showinfo/warning/error,askquestion/okcancel/yesno/retrycancel
    from tkMessageBox import *
    #Usage:f=tkFileDialog.askopenfilename(initialdir='E:/Python')
    #import tkFileDialog
    #import tkSimpleDialog
else:  #Python 3.x
    PythonVersion = 3
    from tkinter.font import Font
    from tkinter.ttk import *
    from tkinter.messagebox import *
    #import tkinter.filedialog as tkFileDialog
    #import tkinter.simpledialog as tkSimpleDialog    #askstring()

class Application_ui(Frame):
    #这个类仅实现界面生成功能,具体事件处理代码在子类Application中。
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master.title('自动关机')
        self.master.geometry('519x135')
        self.createWidgets()

    def createWidgets(self):
        self.top = self.winfo_toplevel()
        self.style = Style()
        self.Text1Var = StringVar(value='')
        self.Text1 = Entry(self.top, textvariable=self.Text1Var, font=('宋体',9))
        self.Text1.place(relx=0.293, rely=0.119, relwidth=0.449, relheight=0.304)

        self.style.configure('Command1.TButton',font=('宋体',9))
        self.Command1 = Button(self.top, text='确定', command=self.Command1_Cmd, style='Command1.TButton')
        self.Command1.place(relx=0.123, rely=0.593, relwidth=0.326, relheight=0.304)

        self.style.configure('Label1.TLabel',anchor='w', font=('宋体',22))
        self.Label1 = Label(self.top, text='系统将在', style='Label1.TLabel')
        self.Label1.place(relx=0.015, rely=0.178, relwidth=0.249, relheight=0.244)

        self.style.configure('Label2.TLabel',anchor='w', font=('宋体',22))
        self.Label2 = Label(self.top, text='秒后关机', style='Label2.TLabel')
        self.Label2.place(relx=0.755, rely=0.178, relwidth=0.295, relheight=0.244)

        self.style.configure('Command2.TButton',font=('宋体',9))
        self.Command2 = Button(self.top, text='取消', command=self.Command2_Cmd, style='Command2.TButton')
        self.Command2.place(relx=0.493, rely=0.593, relwidth=0.31, relheight=0.304)

   

class Application(Application_ui):
    #这个类实现具体的事件处理回调函数。界面生成代码在Application_ui中。
    def __init__(self, master=None):
        Application_ui.__init__(self, master)

    def Command1_Cmd(self, event=None):
        num=self.Text1Var.get()
        try:
                res = float(num)
                cmd="shutdown -s -t "+num
                os.system(cmd)
                wd="系统将在"+num+"秒后关机!按取消键取消"
                showinfo(title = '提示', message = wd)
                pass
        except ValueError as e:
                showinfo(title = '提示', message = '请输入数字')
                raise
        finally:
                pass

    def Command2_Cmd(self, event=None):
        wd2="shutdown -a"
        os.system(wd2)
        showinfo(title='提示',message='已经取消')
        pass

if __name__ == "__main__":
    top = Tk()
    Application(top).mainloop()
    try: top.destroy()
    except: pass


大佬们,这代码有问题吗,为什么在idle里面功能是正常的,pyinstall -F -w 编译后功能什么的都不好用了

3.PNG
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-11-1 18:25:43 | 显示全部楼层
既然是与界面交互,那肯定少不了线程。查下线程的相关资料吧。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-11-1 18:25:57 | 显示全部楼层
既然是与界面交互,那肯定少不了线程。查下线程的相关资料吧。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-11-3 17:51:02 | 显示全部楼层
如何正确地发代码、上传图片和附件?
https://fishc.com.cn/thread-52272-1-1.html
(出处: 鱼C论坛——小甲鱼)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-20 11:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表