import tkinter as tk

class APP:
    def __init__(self,master):
        frame = tk.Frame(master)
        frame.pack(side = tk.LEFT,padx=50,pady=50)

        self.hi_there = tk.Button(frame,text ="打招呼",bg = "blue",fg = "white",command = self.say_hi)
        self.hi_there.pack()

    def say_hi(self):
        print("Hello World!")

root = tk.Tk()
app = APP(root)

root.mainloop()

 

 

from tkinter import*
def callback():
    var.set("No!")
root = Tk()

frame1 = Frame(root)
frame2 = Frame(root)
var = StringVar()
var.set("Sorry!\nThere is someting Wrong!")

textLabel = Label(frame1,
                  textvariable = var,
                  justify = LEFT)
textLabel.pack(side=LEFT)

photo = PhotoImage(file = "18.gif")
imLabel = Label(frame1,image = photo)
imLabel.pack(side = LEFT)

theButton = Button(frame2,text = "I am OK !",command = callback)
theButton.pack()

'''
photo = PhotoImage(file = "bg.gif")
theLabel = Label(root,
                 text = "学 Python\n到 FichC",
                 justify = LEFT,
                 image = photo,
                 compound = CENTER,
                 fg = "white")
theLabel.pack()
'''
frame1.pack(padx = 10,pady = 10)
frame2.pack(padx = 10,pady = 10)
mainloop()

 

相关文章:

  • 2021-12-05
  • 2021-05-11
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2021-05-21
猜你喜欢
  • 2021-06-26
  • 2021-07-15
  • 2021-09-14
  • 2021-06-21
  • 2021-12-21
  • 2022-12-23
  • 2021-09-16
相关资源
相似解决方案