python-在tkinter中更改帧的大小,这是由一个类定义的
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-在tkinter中更改帧的大小,这是由一个类定义的,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3143字,纯文字阅读大概需要5分钟。
内容图文
![python-在tkinter中更改帧的大小,这是由一个类定义的](/upload/InfoBanner/zyjiaocheng/686/4b87a8b5f6d745afb612a777ddeac2b6.jpg)
我正在尝试将帧的大小更改为tkinter;我正在使用python 3.0,并且正在为学校项目创建库存管理类型的东西.这是我现在拥有的代码,我正在尝试编辑框架的尺寸.我试图上网查找,但是找不到所需的信息.我知道您需要使用:
.geomtry()
内置函数,但是我不知道将它放在哪里,或者如何在类中使用它.
import tkinter as tk
LARGE_FONT= ("Comic Sans MS", 12)
SMALL_FONT=('Comic sans ms', 8)
class StockManager(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
lbl1 = tk.Label(self, text='Welcome to the stock manager', font=LARGE_FONT)
lbl1.pack(pady=10, padx=10)
lbl2 = tk.Label(self, text='What would you like to do?', font=LARGE_FONT)
lbl2.pack(pady=10, padx=10)
btnShowProducts = tk.Button(self, text='1. Show all products ', font=LARGE_FONT,)
btnShowProducts.pack(anchor='w')
btnSearchProducts = tk.Button(self, text='2. Search for a product ', font=LARGE_FONT)
btnSearchProducts.pack(anchor='w')
btnAddProduct = tk.Button(self, text='3. Add another product ', font=LARGE_FONT)
btnAddProduct.pack(anchor='w')
btnDeleteProduct = tk.Button(self, text='4. Delete a product ', font=LARGE_FONT)
btnClose = tk.Button(self, text='Close Database ', font=LARGE_FONT)
btnClose.pack(anchor='w')
btnNextPage = tk.Button(self, text='Next Page', font=SMALL_FONT)
btnNextPage.pack(anchor='s')
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
label.pack(pady=10, padx=10)
btnAddTrans = tk.Button(self, text='1. Add a new transaction', font=('comic sans ms', 10)) ##CREATE ADD TRANSACTION HERE
btnShowTrans = tk.Button(self, text='2. Show Transactions', font=('Comic Sans MS', 10))
btnShowTrans.pack(anchor='w')
button1 = tk.Button(self, text="Back to Home")
button1.pack()
button2 = tk.Button(self, text="Next Page")
button2.pack()
menu = StockManager()
menu.mainloop()
解决方法:
这是一个简单的示例,说明如何使用geometry()方法调整窗口大小.这应该可以帮助您了解它在班级中的工作方式.
import tkinter as tk
class My_App(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
# we need to set parent as a class attribute for later use
self.parent = parent
button1 = tk.Button(self.parent, text="Make window larger!", command = self.make_window_bigger)
button1.pack()
button2 = tk.Button(self.parent, text="Make window Smaller!", command = self.make_window_smaller)
button2.pack()
def make_window_bigger(self):
x = self.parent.winfo_height() + 10
y = self.parent.winfo_width() + 10
self.parent.geometry('{}x{}'.format(y, x))
def make_window_smaller(self):
x = self.parent.winfo_height() - 10
y = self.parent.winfo_width() - 10
self.parent.geometry('{}x{}'.format(y, x))
root = tk.Tk()
My_App(root)
root.mainloop()
内容总结
以上是互联网集市为您收集整理的python-在tkinter中更改帧的大小,这是由一个类定义的全部内容,希望文章能够帮你解决python-在tkinter中更改帧的大小,这是由一个类定义的所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。