Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Tkinter window pop up again when i click button
Hi guys, im new at python and new at programming code.
i got confused when run a little program that i created on.
so it pop up again when i click "run service", did i miss something ? thx.

source code :

from tkinter import *
# from Outdated_Versions import server as outdated_Server

class HttpServer:

    def __init__(self,root):
        self.LabelProject = Label(root, text="HTTP Server Project Using Python")
        self.LabelProject2 = Label(root, text="Kelompok 2 - HTTP")
        self.label_1 = Label(root, text="IP Address / HOST")
        self.label_2 = Label(root, text="PORT")

        # self.entryIP = StringVar()
        # self.entryIP = IntVar()

        self.entryIP = Entry(root)
        self.entryPORT = Entry(root)

        # self.EntryIP_Str =
        # self.EntryPORT_Int =
        # Normally, the characters that the
        # user types appear in the entry.To
        # make a.password.entry that echoes
        # each character as an asterisk, set
        # show = "*".
        self.chkFrame = BooleanVar()
        self.FrameSettingsModule = Checkbutton(root, var=self.chkFrame )
        self.labelFrameSettingsModule = Label(root, text="Use FLASK Framework")
        self.chkDefault = BooleanVar()
        self.defaultSettingsModule = Checkbutton(root, var=self.chkDefault, command=self.cacheDefault )
        self.labeldefaultSettingsModule = Label(root, text="Use Default Settings")
        self.chkSave = BooleanVar()
        self.saveSettingsModule = Checkbutton(root, var=self.chkSave)
        self.labelsaveSettingsModule = Label(root, text="Save Settings")
        self.button_Process = Button(root, text="Run Service", fg="green", command=self.ButtonPress )
        self.button_Exit = Button(root, text="Stop Service", fg="red")

        self.LabelProject.grid(row=0, columnspan=2)
        self.LabelProject2.grid(row=1, columnspan=2)
        self.label_1.grid(row=2, sticky=W)
        self.label_2.grid(row=3, sticky=W)
        self.entryIP.grid(row=2, column=1)
        self.entryPORT.grid(row=3, column=1)
        self.labelFrameSettingsModule.grid(row=4, column=1)
        self.labeldefaultSettingsModule.grid(row=5, column=1)
        self.labelsaveSettingsModule.grid(row=6, column=1)
        self.button_Exit.grid(row=7, column=1)

    def cacheDefault(self):
        self.varCheckDefault = self.chkDefault.get()
        self.varCheckFrame = self.chkFrame.get()

        if self.varCheckDefault == True:
            self.entryIP.delete(0, END)
            self.entryIP.insert(0, "localhost")
            self.entryPORT.delete(0, END)
            self.entryPORT.insert(0, 80)
            self.entryIP.delete(0, END)
            self.entryPORT.delete(0, END)

    def ButtonPress(self):
        self.varCheckDefault = self.chkDefault.get()
        self.varCheckFrame = self.chkFrame.get()
        IP = self.entryIP.get()
        PORT = self.entryPORT.get()
        if self.varCheckFrame == True:
            if IP == 'localhost':
                IP = ''
            if self.varCheckDefault == True:
                # self.callServer(PORT)
                print("You need Checklist the Default Settings with the Old Version!")

    def callServer(self,PORT):
        from http.server import HTTPServer, BaseHTTPRequestHandler
        class Server(BaseHTTPRequestHandler):
            def do_GET(self):
                if self.path == '/':
                    self.path = '/index.html'
                    file_to_open = open(self.path[1:]).read()
                    file_to_open = "File not found"
                self.wfile.write(bytes(file_to_open, 'utf-8'))
        httpd = HTTPServer(('',PORT), Server)

    def Framework(self,IP,PORT):
        IP = self.entryIP.get()
        PORT = self.entryPORT.get()
            from flask import Flask
            app = Flask(__name__)
            def main():
                return "Welcome to my Flask page!"
            if __name__ == "__main__":
      , host=IP, port=PORT)
        except ModuleNotFoundError:
            print('Your Flask Framework is not installed!, please install it with "pip3 install flask"')
            print('Error! please check the code and connection!')

master = Tk()
frame = Frame(master, width=125, height=35)
master.resizable(False, False)
master.title("HTTP Server")


callInit = HttpServer(master)
buran wrote May-09-2019, 04:35 PM:
I post your code here in python tags, change title to meaningful one and moved the thread to correct sub-forum
worked for me with the callServer function commented.
I'm using linux, 3.5 idle
Did you run from console? or pycharm only?
I did notice a problem, when you get the port entry widget it's returning a string and port needs to be converted to integer. (int(PORT)) then the web server threw an error asking for permission.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Tkinter button in for Simpsunt 1 15 5 hours ago
Last Post: Larz60+
  tkinter window and turtle window error 1885 3 165 Nov-02-2019, 12:18 PM
Last Post: 1885
  [Tkinter] Checking button click in Tkinter GalaxyCoyote 3 194 Oct-20-2019, 03:28 AM
Last Post: GalaxyCoyote
  [Tkinter] Tkinter button help and general commands Iceman 1 199 Sep-01-2019, 05:09 PM
Last Post: Yoriz
  [Tkinter] Extrakt a Variable from a closed tkinter window hWp 5 296 Aug-23-2019, 09:01 PM
Last Post: woooee
  [PyQt] Problem how to click a button inside a group box? mart79 2 221 Aug-05-2019, 01:21 PM
Last Post: mart79
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 365 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] Not getting entry values on button click & treeview not updating ? swanysto 4 1,043 May-10-2019, 04:16 PM
Last Post: swanysto
  [Tkinter] Top Level Window - from tkinter import * francisco_neves2020 6 558 Apr-23-2019, 09:27 PM
Last Post: francisco_neves2020
  [WxPython] Adding a Window to a Button wxPython ShashankDS 4 554 Apr-23-2019, 06:53 PM
Last Post: Yoriz

Forum Jump:

Users browsing this thread: 1 Guest(s)