python的GUI编程之Grid布局的使用

import tkinter as tk
from tkinter import ttk


class Application():

    def __init__(self, master):
        self.master = master
        self.initWidgets()

    def initWidgets(self):

        input1 = tk.Entry(master=self.master, relief=tk.SUNKEN, font=('Courier New', 24), width=25, fg="blue")
        input1.pack(side=tk.TOP, pady=10)
        label = tk.Label(master=self.master, text="结果")
        label.pack(side=tk.TOP)
        # input2 = tk.Entry(master=self.master, relief=tk.SUNKEN, font=('Courier New', 24), width=25, show="*",fg="blue", state=tk.DISABLED)
        input2 = tk.Entry(master=self.master, relief=tk.SUNKEN, font=('Courier New', 24), width=25, fg="blue", state=tk.DISABLED)
        input2.pack(side=tk.TOP, pady=10)
        p2 = tk.Frame(self.master)
        p2.pack(side=tk.TOP)
        names = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", ".", "=")
        # 遍历字符串元组
        for i in range(len(names)):
            b = tk.Button(p2, text=names[i], font=('Verdana', 20), width=6)
            print(i // 4, i % 4)
            b.grid(row=i // 4, column=i % 4)


root = tk.Tk()
root.title("Grid布局")
Application(root)
root.mainloop()



上一篇:如何学Java


下一篇:jmeter非GUI模式压测并生成测试报告