python3.6.x 爬糗事百科(tkinter+PAGE) GUI版

今天又好好的研究了一下python tkinter,怎么样才能做得好看好用呢?如果只是常规方法实在是有点难度(用代码来写界面布局 )着实太难了)。上网搜了很久,终于找出了一款,不过不太好看,但确实能生出好看的界面。GUI代码得自己在生成的GUI代码中找寻,但是感觉不错,立即行动起用,将之前写的糗事百科整了个GUI,感觉好看多了。

如要做用这个tool(PAGE),请参考以下两个站点自行下载.
1. PAGE
http://page.sourceforge.net/
2. Tcl(8.6+)
https://www.activestate.com/activetcl/downloads

具体怎么应用这两个工具来整出好看的GUI呢?我好好整理一下,下个blog写个教程出来,先上今天整的糗事百科的界面, 感受一下它的美:


生成GUI的主要代码如下:

        disContentText = Text()
        disContentText.place(relx=0.01, rely=0.29, relheight=0.58, relwidth=0.98)
        disContentText.configure(background="white")
        disContentText.configure(font="TkTextFont")
        disContentText.configure(foreground="black")
        disContentText.configure(highlightbackground="#d9d9d9")
        disContentText.configure(highlightcolor="black")
        disContentText.configure(insertbackground="black")
        disContentText.configure(selectbackground="#c4c4c4")
        disContentText.configure(selectforeground="black")
        disContentText.configure(width=584)
        disContentText.configure(wrap=WORD)
        
        #当启动应用后先显示第一条糗百
        firstList = self.getOneHappy()
        self.openurl = firstList[-1].strip()
        disContentText.insert('insert', self.list2String(self.getOneHappy()))
        
        entry = Entry()
        entry.bind('<Return>', onBindentry)
        entry.place(relx=0.03, rely=0.89,height=27, relwidth=0.19)
        entry.configure(background="white")
        entry.configure(disabledforeground="#a3a3a3")
        entry.configure(font="TkFixedFont")
        entry.configure(foreground="#000000")
        entry.configure(highlightbackground="#d9d9d9")
        entry.configure(highlightcolor="black")
        entry.configure(insertbackground="black")
        entry.configure(selectbackground="#c4c4c4")
        entry.configure(selectforeground="black")

        nextBtn = Button(command=onGetNextBtn)
        nextBtn.place(relx=0.49, rely=0.89, height=28, width=59)
        nextBtn.configure(activebackground="#d9d9d9")
        nextBtn.configure(activeforeground="#000000")
        nextBtn.configure(background="#d9d9d9")
        nextBtn.configure(disabledforeground="#a3a3a3")
        nextBtn.configure(foreground="#000000")
        nextBtn.configure(highlightbackground="#d9d9d9")
        nextBtn.configure(highlightcolor="black")
        nextBtn.configure(pady="0")
        nextBtn.configure(text="下一条")

        openUrl = Button(command=onOpenUrl)
        openUrl.place(relx=0.66, rely=0.89, height=28, width=59)
        openUrl.configure(activebackground="#d9d9d9")
        openUrl.configure(activeforeground="#000000")
        openUrl.configure(background="#d9d9d9")
        openUrl.configure(disabledforeground="#a3a3a3")
        openUrl.configure(foreground="#000000")
        openUrl.configure(highlightbackground="#d9d9d9")
        openUrl.configure(highlightcolor="black")
        openUrl.configure(pady="0")
        openUrl.configure(text='打开链接')

        copyBtn = Button(command=onCopyContent)
        copyBtn.place(relx=0.82, rely=0.89, height=28, width=59)
        copyBtn.configure(activebackground="#d9d9d9")
        copyBtn.configure(activeforeground="#000000")
        copyBtn.configure(background="#d9d9d9")
        copyBtn.configure(disabledforeground="#a3a3a3")
        copyBtn.configure(foreground="#000000")
        copyBtn.configure(highlightbackground="#d9d9d9")
        copyBtn.configure(highlightcolor="black")
        copyBtn.configure(pady="0")
        copyBtn.configure(text='复制内容')

        firmBtn = Button(comman=onConfirm)
        firmBtn.place(relx=0.24, rely=0.89, height=28, width=59)
        firmBtn.configure(activebackground="#d9d9d9")
        firmBtn.configure(activeforeground="#000000")
        firmBtn.configure(background="#d9d9d9")
        firmBtn.configure(disabledforeground="#a3a3a3")
        firmBtn.configure(foreground="#000000")
        firmBtn.configure(highlightbackground="#d9d9d9")
        firmBtn.configure(highlightcolor="black")
        firmBtn.configure(pady="0")
        firmBtn.configure(text='确认')
        
        Label1 = Label()
        Label1.place(relx=0.01, rely=0.01, height=103, width=197)
        Label1.configure(activebackground="#f9f9f9")
        Label1.configure(activeforeground="black")
        Label1.configure(background="#d9d9d9")
        Label1.configure(disabledforeground="#a3a3a3")
        Label1.configure(foreground="#000000")
        Label1.configure(highlightbackground="#d9d9d9")
        Label1.configure(highlightcolor="black")
        Label1.configure(image=self.photo)
        Label1.configure(relief=RIDGE)
        Label1.configure(text='Label')
        
        labelZan = Label()
        labelZan.place(relx=0.4, rely=0.16, height=43, width=170)
        labelZan.configure(activebackground="#f9f9f9")
        labelZan.configure(activeforeground="black")
        labelZan.configure(background="#d9d9d9")
        labelZan.configure(disabledforeground="#a3a3a3")
        labelZan.configure(font=font9)
        labelZan.configure(foreground="#000000")
        labelZan.configure(highlightbackground="#d9d9d9")
        labelZan.configure(highlightcolor="black")
        labelZan.configure(justify=RIGHT)
        labelZan.configure(text='当前对点赞数的限定:')
        
        labelZan_1 = Label()
        labelZan_1.place(relx=0.67, rely=0.16, height=43, width=77)
        labelZan_1.configure(activebackground="#f9f9f9")
        labelZan_1.configure(activeforeground="black")
        labelZan_1.configure(background="#d9d9d9")
        labelZan_1.configure(disabledforeground="#a3a3a3")
        labelZan_1.configure(font=font9)
        labelZan_1.configure(foreground="#000000")
        labelZan_1.configure(highlightbackground="#d9d9d9")
        labelZan_1.configure(highlightcolor="black")
        labelZan_1.configure(justify=RIGHT)
        labelZan_1.configure(text='0')

如果想要查看完整代码(包括第三方software PAGE+Tcl8.6+),请进入如下链接获取:

https://pan.baidu.com/s/1gl_Ln75UZhVvrk1q8LSMjw  (比较完整)

也可以在我的github上获取,但只有py档.

https://github.com/vitamincqb/Toolset

猜你喜欢

转载自blog.csdn.net/lxy210781/article/details/81047765