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

2021/10/17 14:11:05

本文主要是介绍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()





这篇关于python的GUI编程之Grid布局的使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程