0

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

How can I place other modules in my main page? enter image description here

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

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

below is my main page code

from tkinter import *
import Factor
import conversion

mainPage = Tk()

mainPage.mainloop()

"Factor.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()

"conversion.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()

hope this will clear my query

stovfl
  • 14,998
  • 7
  • 24
  • 51
Anon Dorse
  • 13
  • 6
  • Asterisk/`*` imports are discouraged. – AMC Jan 26 '20 at 19:14
  • @AnonDorse Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged), [Tkinter understanding mainloop](https://stackoverflow.com/questions/29158220/tkinter-understanding-mainloop) and Read up on [Modules](https://docs.python.org/3/tutorial/modules.html#modules) – stovfl Jan 27 '20 at 11:08
  • @AnonDorse I think there are only a few facts stopping you from what you want to achieve. Can you please explain a little bit more about what output you actually want. I might be able to help you then. – DaniyalAhmadSE Jan 27 '20 at 12:46
  • @DaniyalAhmad hi sir thanks for your attention, i trying to import my 2 modules in mainpage the problem is that when i run the mainpage it will pop up my 2 module which separate in my mainpage which not what im trying to achieve. you can the above picture that was may target to be done. when i run my mainpage it should plug-in in my mainpage window not separate. – Anon Dorse Jan 27 '20 at 13:04

1 Answers1

0

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.

DaniyalAhmadSE
  • 807
  • 11
  • 20
  • 1
    @Daniyal Ahmad, thank you is working and this is what i'm looking for, however when i put the function example in Factor.py, it doesn't works when i click the check button in mainpage, do you have an idea about it? – Anon Dorse Jan 27 '20 at 20:56
  • @AnonDorse Can you please tell me what function are you giving to the `Button` as the `command`? – DaniyalAhmadSE Jan 28 '20 at 07:50
  • @AnonDorse please edit your question and also post the function which you are trying to give to your `Button` as `command`. Or you can ask a new question for that as the problem listed in this question is fixed. So the choice is yours. :) – DaniyalAhmadSE Jan 28 '20 at 07:55
  • 1
    thank you very much all my query is solved appreciated your effort sir. i do hope you will find my future query here so that will surely resolved :) – Anon Dorse Jan 28 '20 at 11:39
  • @AnonDorse have you posted a new question about that? – DaniyalAhmadSE Jan 28 '20 at 13:59
  • @AnonDorse Good to hear. :) – DaniyalAhmadSE Jan 29 '20 at 14:13
  • @Dariyal Ahmad sir kindly help me for this. https://stackoverflow.com/questions/60073322/multi-diary-in-tkinter – Anon Dorse Feb 05 '20 at 10:07
  • @AnonDorse Sorry I was offline for a few days I will take a look at it. – DaniyalAhmadSE Feb 08 '20 at 08:14