在主页中导入另一个模块 [英] Import another module in Main Page

查看:28
本文介绍了在主页中导入另一个模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理我的任务,有人可以帮助我吗?

I'm working with my assignment, can someone help me?

如何在我的主页中放置其他模块?

How can I place other modules in my main page?

因为现在这个主页代码,一旦我运行不好的主页它就会弹出2个模块.

because this mainpage code now, it will pop up the 2 modules once i run the mainpage which is not good.

我想要的是在我的主页中插入这 2 个模块,这样我就可以在我的主页中使用这 2 个模块

what i want is to insert this 2 modules in my mainpage so i can use these 2 module in my mainpage

下面是我的主页代码

from tkinter import *
import Factor
import conversion

mainPage = Tk()

mainPage.mainloop()

因子.py"

import tkinter as tk


window = tk.Tk()
topFrame=tk.Frame(window)
midFrame=tk.Frame(window)
belowFrame=tk.Frame(window)
titlePage = tk.Label(window,text = 'Prime Factor')
titlePage.pack()
entNum = tk.Label(topFrame,text='Enter a number:')
entNum.pack(side='left')
entryInput = tk.Entry(topFrame)
entryInput.pack(side = 'left')

btn = tk.Button(midFrame,text = 'Check')
btn.pack()
tk.Label(midFrame,text = 'The prime Factors are :',font=("Times new roman",10)).pack()

topFrame.pack(side = 'top')
midFrame.pack(side = 'top')
belowFrame.pack(side = 'bottom')
window.mainloop()

转换.py"

from tkinter import *

root = Tk()

numOne=Label(root, text="Enter Value 1").grid(row=0, sticky=W)
numTwo=Label(root, text="Enter Value 2").grid(row=1, sticky=W)

addTotal=Label(root, text="The sum is :").grid(row=3, sticky=W)


enterEntry1 = Entry(root)
enterEntry2 = Entry(root)
enterEntry1.grid(row=0, column=1)
enterEntry2.grid(row=1, column=1)

Calcu = Button(root, text="Calculate").grid(row=7, column=1)

root.mainloop()

希望这会清除我的查询

推荐答案

这里有一个解决方案:

主页:

import tkinter as tk
import factor
import conversion
import swapping
import year

mainPage = tk.Tk()

swapping.swap(mainPage)
factor.fac(mainPage)
conversion.con(mainPage)
year.ye(mainPage)

mainPage.mainloop()

因素:

def fac(win):
    import tkinter as tk

    factor_frame = tk.Frame(win, borderwidth=100, highlightbackground="black", highlightthickness=2)
    factor_frame.grid(row=0, column=1)
    topFrame = tk.Frame(factor_frame)
    midFrame = tk.Frame(factor_frame)
    belowFrame = tk.Frame(factor_frame)
    titlePage = tk.Label(factor_frame, text='Prime Factor')
    titlePage.pack()
    entNum = tk.Label(topFrame, text='Enter a number:')
    entNum.pack(side='left')
    entryInput = tk.Entry(topFrame)
    entryInput.pack(side='left')

    btn = tk.Button(midFrame, text='Check')
    btn.pack()
    tk.Label(midFrame, text='The prime Factors are :', font=("Times new roman", 10)).pack()

    topFrame.pack(side='top')
    midFrame.pack(side='top')
    belowFrame.pack(side='bottom')

转化:

def con(win):
    import tkinter as tk

    conversion_frame = tk.Frame(win, borderwidth=100, highlightbackground="black", highlightthickness=2)
    conversion_frame.grid(row=1, column=0, ipadx=0, ipady=1, sticky='s')

    numOne = tk.Label(conversion_frame, text="Enter Value 1").grid(row=0, sticky='W')
    numTwo = tk.Label(conversion_frame, text="Enter Value 2").grid(row=1, sticky='W')

    addTotal = tk.Label(conversion_frame, text="The sum is :").grid(row=3, sticky='W')

    enterEntry1 = tk.Entry(conversion_frame)
    enterEntry2 = tk.Entry(conversion_frame)
    enterEntry1.grid(row=0, column=1)
    enterEntry2.grid(row=1, column=1)

    Calcu = tk.Button(conversion_frame, text="Calculate").grid(row=7, column=1)

交换:

def swap(win):
    import tkinter as tk

    swapping_frame = tk.Frame(win, borderwidth=100, highlightbackground="black", highlightthickness=2)
    lbl = tk.Label(swapping_frame, text='SWAPPING', font=40).grid(row=0, column=0)
    swapping_frame.grid(row=0, column=0)

年份:

def ye(win):
    import tkinter as tk

    year_frame = tk.Frame(win, borderwidth=100, highlightbackground="red", highlightthickness=2)
    lbl = tk.Label(year_frame, text='YEAR', font=40).grid(row=1, column=1)
    year_frame.grid(row=1, column=1)

我以某种方式解决了您的问题.主要问题是您多次使用 Tk() 用于创建新窗口,而您试图将内容放入现有窗口中,因此它造成了冲突.我认为您应该观看一些 tkinter 教程,它们对您的帮助比什么都重要.

I have somehow solved your issue. The main issue was that you were using Tk() more than once which is used to create a new window while you were trying to put the stuff in the existing window, So it was creating a conflict. I think you should watch some tkinter tutorials that will help you more than anything else.

这篇关于在主页中导入另一个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆