Fedora15下配置Tkinter开发环境

时间:2022-05-08 01:47:14

目的:使用Python开发UI程序

尝试了使用PyQt, PyGTK, PyX11, 发现对于初学者来说,还是使用Python原生的Tkinter来的简单,因为其他方式安装起来相对来说比较复杂,对于初学者,我还是建议使用Tkinter.

使用yum命令安装相关的软件包,尝试写了第一个Tkinter的hello world程序,发现报错:No package Tkinter available,
于是yum install tkinter

这样,我的第一个hello world运行成功了!

from Tkinter import *    #导入Tkinter模块

class Application(Frame):
    def say_hi(self):
        print "hi there, everyone!"
    def createWidgets(self):
        self.QUIT = Button(self)
        self.QUIT["text"] = "QUIT"
        self.QUIT["fg"] = "red"
        self.QUIT["command"] = self.quit
        
        self.QUIT.pack({"side": "left"})

        self.hi_there = Button(self)
        self.hi_there["text"] = "Hello"
        self.hi_there["command"] = self.say_hi
        
        self.hi_there.pack({"side": "left"})

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()


root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()