Skip to content Skip to sidebar Skip to footer

Import Another Module In Main Page

I'm working with my assignment, can someone help me? How can I place other modules in my main page? because this mainpage code now, it will pop up the 2 modules once i run the ma

Solution 1:

Here's a solution for you:

Main Page:

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()

Factor:

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')

Conversion:

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)

Swapping:

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)

Year:

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)

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.


Post a Comment for "Import Another Module In Main Page"