Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

Re: Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

โดย Issuresix » 19/07/2018 2:35 pm

ผมก็เคยติดปัญหานี้อยู่เหมือนกันครับ

Re: Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

โดย rangsan » 18/05/2018 7:05 pm

nuattawoot เขียน:ลองใช้แบบนี้ ว่าได้ปล่าว

โค้ด: เลือกทั้งหมด

def log(self):
        self.username.set('ใส่ที่ต้องการ')
        self.password.set('ใส่ที่ต้องการ')
     self.logf.pack()
ทำได้แล้วครับ ขอบคุณมากครับ

Re: Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

โดย nuattawoot » 18/05/2018 6:51 pm

ลองใช้แบบนี้ ว่าได้ปล่าว

โค้ด: เลือกทั้งหมด

def log(self):
        self.username.set('ใส่ที่ต้องการ')
        self.password.set('ใส่ที่ต้องการ')
     self.logf.pack()

Q - ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

โดย rangsan » 18/05/2018 6:30 pm

ต้องการที่จะทำการ Set ค่าให้กับตัว Python GUI( Tkinter )

ภาพตัวอย่างสิ่งที่ต้องการจะทำ
Selection_088.png
Selection_088.png (27.69 KiB) Viewed 1611 times
จากาพต้องการ Set ค่าให้กับตัว Edit Text เมื่อทำการ Run โปรแกรม ให้มีค่า ตามที่เรากำหนดเลย

เช่น Hostname : localhost
Database : Database
Username : User1
Password : *******
Web Driver Path : Your Path

โค้ดในส่วนของหน้าต่าง Login

โค้ด: เลือกทั้งหมด

class main():
    def __init__(self,master):
        self.master = master
        self.username =  StringVar()
        self.password =  StringVar()
        self.hostname =  StringVar()
        self.database =  StringVar()
        self.pathwebdriver = StringVar()
        self.widgets()

    def selection(self):
        root.filename = filedialog.askopenfile(initialdir = "/",title = "Select file",filetypes = (("files","*.exe"),("all files","*.*")))
        fname = root.filename.name
        self.pathwebdriver.set(fname)

    def login(self):
        link = self.hostname.get() + "/?db=" + self.database.get()
        __builtin__.base_url = link
        __builtin__.chromedriver = self.pathwebdriver.get()
        __builtin__.username = self.username.get()
        __builtin__.pwd = self.password.get()
        __builtin__.db_name = self.database.get()

        suite = unittest.TestLoader().loadTestsFromModule(alloy_all)
        unittest.TextTestRunner(verbosity=2).run(suite)

    def widgets(self):

        self.head = Label(self.master,text = 'LOGIN',font = ('',25),pady = 10)
        self.head.pack()
        self.logf = Frame(self.master,padx =10,pady = 10)
        Label(self.logf,text='Host Name', font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.hostname,bd = 5,font = ('',15)).grid(row=0,column=1)
        Label(self.logf,text = 'Database  ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.database,bd = 5,font = ('',15)).grid(row=1,column=1)
        Label(self.logf,text='Username',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.username,bd = 5,font = ('',15)).grid(row=2,column=1)
        Label(self.logf,text = 'Password   ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15),show = '*').grid(row=3,column=1)
        Label(self.logf,text = 'Path Webdriver ',font = ('',20),pady=5,padx=5 ).grid(sticky = W)
        Entry(self.logf,textvariable = self.pathwebdriver,bd = 5,font = ('',15)).grid(row=4,column=1)
        Button(self.logf,text = ' RUN ',bd = 3 ,font = ('',12),padx=5,pady=5, command=self.login).grid(row=7,column=1)
        Button(self.logf,text = ' Browse ' ,bd = 3 ,font = ('',10),padx=5,pady=5, command=self.selection).grid(row=4,column=2)
        Button(self.logf,text = ' Close ',bd = 3 ,font = ('',12),padx=5,pady=5, command=root.destroy).grid(row=7,column=2)
        self.logf.pack()

if __name__ == '__main__':

    root = Tk()
    root.title('Alloy Login')
    main(root)
    root.mainloop()
อยากทราบวิธีครับ

ข้างบน