<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Python中使用Tkinter模塊創建GUI程序實例

        來源:懂視網 責編:小采 時間:2020-11-27 14:40:27
        文檔

        Python中使用Tkinter模塊創建GUI程序實例

        Python中使用Tkinter模塊創建GUI程序實例:使用Tkinter模塊來創建簡單的GUI程序。 Tkinter的Widgets有:Button、Canvas、Checkbutton、Entry、Frame、Label、Listbox、Menu、Menubutton、Message、Radiobutton、Scales、Scrollbar、TEXT、Toplevel等。 例: 代
        推薦度:
        導讀Python中使用Tkinter模塊創建GUI程序實例:使用Tkinter模塊來創建簡單的GUI程序。 Tkinter的Widgets有:Button、Canvas、Checkbutton、Entry、Frame、Label、Listbox、Menu、Menubutton、Message、Radiobutton、Scales、Scrollbar、TEXT、Toplevel等。 例: 代

        使用Tkinter模塊來創建簡單的GUI程序。

        Tkinter的Widgets有:Button、Canvas、Checkbutton、Entry、Frame、Label、Listbox、Menu、Menubutton、Message、Radiobutton、Scales、Scrollbar、TEXT、Toplevel等。

        例:

        代碼如下:


        # This program displays an empty window.
        import Tkinter
        def main():
        main_window = Tkinter.Tk()
        Tkinter.mainloop()
        main()


        例2:

        代碼如下:


        import Tkinter
        class MyGUI:
        def __init__(self):
        # Create the main window widget.
        self.main_window = Tkinter.Tk()

        # Enter the Tkinter main loop.
        Tkinter.mainloop()
        # Create an instance of the MyGUI class.
        my_gui = MyGUI()


        例3:

        代碼如下:


        # The program displays a label with text.
        import Tkinter
        class MyGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        # Create a Label widget containing the text 'Hello world'
        self.label = Tkinter.Label(self.main_window, text='Hello World!')
        # Call the Label widget's pack method.
        self.label.pack()
        # Enter the Tkinter main loop.
        Tkinter.mainloop()
        # Create an instance of the MyGUI class.
        my_gui = MyGUI()


        例4:

        代碼如下:


        import Tkinter
        class MyGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        self.label1 = Tkinter.Label(self.main_window,text='Hello World!')
        self.label2 = Tkinter.Label(self.main_window,text='This is my GUI program.')
        self.label1.pack()
        self.label2.pack()
        Tkinter.mainloop()
        mygui = MyGUI()


        例5:

        代碼如下:


        import Tkinter
        class MyGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        self.label1 = Tkinter.Label(self.main_window,text='Hello World!')
        self.label2 = Tkinter.Label(self.main_window,text='This is my GUI program.')
        self.label1.pack(side='left')
        self.label2.pack(side='left')
        Tkinter.mainloop()
        mygui = MyGUI()


        例6:

        代碼如下:


        import Tkinter
        class MyGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        self.top_frame = Tkinter.Frame(self.main_window)
        self.bottom_frame = Tkinter.Frame(self.main_window)
        self.label1 = Tkinter.Label(self.top_frame,text='Winken')
        self.label2 = Tkinter.Label(self.top_frame,text='Blinken')
        self.label3 = Tkinter.Label(self.top_frame,text='Nod')

        self.label1.pack(side='top')
        self.label2.pack(side='top')
        self.label3.pack(side='top')

        self.label4 = Tkinter.Label(self.bottom_frame,text='Winken')
        self.label5 = Tkinter.Label(self.bottom_frame,text='Blinken')
        self.label6 = Tkinter.Label(self.bottom_frame,text='Nod')

        self.label4.pack(side='left')
        self.label5.pack(side='left')
        self.label6.pack(side='left')

        self.top_frame.pack()
        self.bottom_frame.pack()

        Tkinter.mainloop()
        mygui = MyGUI()


        按鈕Widget和信息對話框
        使用tkMessageBox模塊的showinfo函數來顯示信息對話框。
        例:

        代碼如下:


        # the program demonstrates a Button widget.
        # when the user clicks the button, an info dialog box is displayed.
        import Tkinter
        import tkMessageBox
        class MyGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        self.my_button = Tkinter.Button(self.main_window, text='Click me!',command=self.do_something)
        self.my_button.pack()
        Tkinter.mainloop()
        def do_something(self):
        tkMessageBox.showinfo('Response','Thanks for clicking the button.')
        mygui = MyGUI()


        例2:

        代碼如下:


        import Tkinter
        import tkMessageBox
        class MyGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        self.my_button = Tkinter.Button(self.main_window, text='Click me!',command=self.do_something)
        self.quit_button = Tkinter.Button(self.main_window,text='Quit',command=self.main_window.quit)
        self.my_button.pack()
        self.quit_button.pack()
        Tkinter.mainloop()
        def do_something(self):
        tkMessageBox.showinfo('Response','Thanks for clicking the button.')
        mygui = MyGUI()


        用Entry Widget得到輸入
        Entry Widget是一個矩形區域,用戶可輸入其中。可使用Entry Widget的get方法取回輸入的數據。
        例:

        代碼如下:


        import Tkinter
        import tkMessageBox
        class KiloGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        self.top_frame = Tkinter.Frame(self.main_window)
        self.bottom_frame = Tkinter.Frame(self.main_window)
        self.label = Tkinter.Label(self.top_frame,text='Enter a distance in kilometers:')
        self.entry = Tkinter.Entry(self.top_frame,width=10)
        self.button1 = Tkinter.Button(self.bottom_frame,text='Convert',command=self.convert)
        self.button2 = Tkinter.Button(self.bottom_frame,text='Quit',command=self.main_window.quit)

        self.label.pack(side='left')
        self.entry.pack(side='left')
        self.button1.pack(side='left')
        self.button2.pack(side='left')
        self.top_frame.pack()
        self.bottom_frame.pack()

        Tkinter.mainloop()
        def convert(self):
        kilo = float(self.entry.get())
        miles = kilo*0.6214
        tkMessageBox.showinfo('Result',str(kilo)+' kilometers is equal to '+str(miles)+' miles.')

        mygui = KiloGUI()


        例2:

        代碼如下:


        import Tkinter
        import tkMessageBox
        class KiloGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        self.top_frame = Tkinter.Frame(self.main_window)
        self.mid_frame = Tkinter.Frame(self.main_window)
        self.bottom_frame = Tkinter.Frame(self.main_window)

        self.label1 = Tkinter.Label(self.top_frame,text='Enter a distance in kilometers:')
        self.entry = Tkinter.Entry(self.top_frame,width=10)

        self.button1 = Tkinter.Button(self.bottom_frame,text='Convert',command=self.convert)
        self.button2 = Tkinter.Button(self.bottom_frame,text='Quit',command=self.main_window.quit)

        self.label2 = Tkinter.Label(self.mid_frame,text='Converted to miles:')
        self.value = Tkinter.StringVar()
        self.label3 = Tkinter.Label(self.mid_frame,textvariable=self.value)

        self.label1.pack(side='left')
        self.entry.pack(side='left')

        self.button1.pack(side='left')
        self.button2.pack(side='left')

        self.label2.pack(side='left')
        self.label3.pack(side='left')

        self.top_frame.pack()
        self.mid_frame.pack()
        self.bottom_frame.pack()

        Tkinter.mainloop()
        def convert(self):
        kilo = float(self.entry.get())
        miles = kilo*0.6214
        self.value.set(miles)

        mygui = KiloGUI()


        Radio按鈕和Check按鈕
        例:

        代碼如下:


        import Tkinter
        import tkMessageBox
        class MyGUI:
        def __init__(self):
        self.main_window = Tkinter.Tk()
        self.top_frame = Tkinter.Frame(self.main_window)
        self.bottom_frame = Tkinter.Frame(self.main_window)

        self.radio_var = Tkinter.IntVar()
        self.radio_var.set(1)
        self.rb1 = Tkinter.Radiobutton(self.top_frame,text='Option 1',variable=self.radio_var,value=1)
        self.rb2 = Tkinter.Radiobutton(self.top_frame,text='Option 2',variable=self.radio_var,value=2)
        self.rb3 = Tkinter.Radiobutton(self.top_frame,text='Option 3',variable=self.radio_var,value=3)

        self.rb1.pack()
        self.rb2.pack()
        self.rb3.pack()

        self.ok_button = Tkinter.Button(self.bottom_frame,text='OK',command=self.show_choice)
        self.quit_button = Tkinter.Button(self.bottom_frame,text='QUIT',command=self.main_window.quit)

        self.ok_button.pack(side='left')
        self.quit_button.pack(side='left')

        self.top_frame.pack()
        self.bottom_frame.pack()

        Tkinter.mainloop()

        def show_choice(self):
        tkMessageBox.showinfo('Selection','You selected optioin '+str(self.radio_var.get()))
        mygui = MyGUI()

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Python中使用Tkinter模塊創建GUI程序實例

        Python中使用Tkinter模塊創建GUI程序實例:使用Tkinter模塊來創建簡單的GUI程序。 Tkinter的Widgets有:Button、Canvas、Checkbutton、Entry、Frame、Label、Listbox、Menu、Menubutton、Message、Radiobutton、Scales、Scrollbar、TEXT、Toplevel等。 例: 代
        推薦度:
        標簽: 創建 程序 實例
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 91情国产l精品国产亚洲区| 亚洲AV成人潮喷综合网| 亚洲欧洲第一a在线观看| 国产免费久久精品99久久| 亚洲国产成人久久一区久久 | 亚洲国产午夜电影在线入口| 99ee6热久久免费精品6| 亚洲永久中文字幕在线| 一色屋成人免费精品网站| 亚洲一级毛片中文字幕| 最近中文字幕免费mv视频8| 亚洲欧美日韩国产精品一区| 国产嫩草影院精品免费网址| 男人免费视频一区二区在线观看 | 亚洲熟妇av一区二区三区下载| 亚洲啪啪免费视频| 激情五月亚洲色图| 国产免费av片在线无码免费看| 男人j进女人p免费视频| 久久精品国产亚洲AV麻豆~| 亚洲综合免费视频| 亚洲a∨无码一区二区| 亚洲中文字幕无码爆乳av中文| 久久九九全国免费| 亚洲av永久综合在线观看尤物| 日本特黄特黄刺激大片免费| eeuss在线兵区免费观看| 无码乱人伦一区二区亚洲| 18勿入网站免费永久| 免费在线观看亚洲| 亚洲AV无码久久精品成人| 免费a级毛片无码a∨蜜芽试看| 亚洲变态另类一区二区三区| 国产精品亚洲综合一区| 2021国内精品久久久久精免费| 亚洲欧美成aⅴ人在线观看| 国产精品亚洲精品日韩已满| 2020久久精品国产免费| 丁香花在线观看免费观看图片| 亚洲第一页中文字幕| 亚洲国产精品国产自在在线|