2017年8月26日 星期六

python Tkinter Building a basic GUI


import tkinter

top = tkinter.Tk()

# Code to add widgets will go here...

top.mainloop()




import tkinter
top = tkinter.Tk()

# Code to add widgets will go here...
top.title("Alex Python window")
top.mainloop()




import tkinter
top = tkinter.Tk()

# Code to add widgets will go here...
top.title("Alex Python window")
top.geometry("300x300")
top.wm_iconbitmap("python.ico")
top.mainloop()

設計自己的icon



from tkinter import *
# if you are working under Python 3, comment the previous line and comment out the following line
#from tkinter import *

root = Tk()

w = Label(root, text="Hello Tkinter!")
w.pack()


root.mainloop()



from tkinter import *
# if you are working under Python 3, comment the previous line and comment out the following line
#from tkinter import *

root = Tk()

w = Label(root, text="Hello Tkinter!")
w.pack()

root.mainloop()





from tkinter import *

root = Tk()
logo = PhotoImage(file="python-logo.png")
w1 = Label(root, image=logo).pack(side="right")
explanation = """At present, only GIF and PPM/PGM
formats are supported, but an interface 
exists to allow additional image file
formats to be added easily."""
w2 = Label(root, 
           justify=LEFT,
           padx = 10, 
           text=explanation).pack(side="left")
root.mainloop()




from tkinter import *

root = Tk()
logo = PhotoImage(file="python-logo.png")
explanation = """At present, only GIF and PPM/PGM
formats are supported, but an interface 
exists to allow additional image file
formats to be added easily."""
w = Label(root, 
          compound = CENTER,
          text=explanation, 
          image=logo).pack(side="right")

root.mainloop()



沒有留言:

張貼留言