简体   繁体   English

为什么我不能在框架 tkinter 上放置按钮

[英]Why can't i place a button to a frame tkinter

from tkinter import *

class page:
    def pageNext(self, pageNext):
        self.pageNext = pageNext
        pageNext.tkraise()
    def button(self, window, text, x, y, command = None):
        self.window = window
        self.text = text
        self.x = x
        self.y = y
        self.command = command
        button = Button(window, text = text, command = lambda:command)
        button.place(x = x, y = y)
    def label(self, window, text, x, y, header = False):
        self.window = window
        self.text = text
        self.x = x
        self.y = y
        self.header = header
        if header == True:
            label = Label(window, font = "Helvetica 16 bold italic", text = text)
        else:
            label = Label(window, text = text)
        label.place(x = x, y = y)
    def newPage(self, window):
        self.window = window
        pageNew = Frame(window)
        pageNew.grid(row = 0, column = 0, sticky = "News")
        return pageNew
root = Tk()
page = page()

Guys when I try to create a frame using pageWelcome = page.newPage(root) and place a button using page.button(pageWelcome) and say page.pageNext(pageWelcome) it doesn't place the button but when I place a button like page.button(root) it places the button to the screen.伙计们,当我尝试使用pageWelcome = page.newPage(root)创建一个框架并使用page.button(pageWelcome)放置一个按钮并说page.pageNext(pageWelcome)它没有放置按钮但是当我放置一个按钮时page.button(root)它将按钮放置在屏幕上。 I can't see which part of my code is broken.我看不到我的代码的哪一部分坏了。 Can someone help?有人可以帮忙吗?

PS: I made this class basing to my first GUI. PS:我根据我的第一个 GUI 制作了这个类。 In that times i couldn't use classes but my code was working fine.那时我无法使用类,但我的代码运行良好。

My code我的代码

Guys i couldn't find what was wrong with my code so i started for "how to change page tkinter".伙计们,我找不到我的代码有什么问题,所以我开始学习“如何更改页面 tkinter”。 One of the results was very simple -easy to understand- and i changed all of my code according to that code.结果之一非常简单 - 易于理解 - 我根据该代码更改了所有代码。 I am putting here the tutorial link and the credit link if there is anyone interested.如果有人感兴趣,我将教程链接信用链接放在这里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM